@@ -43,6 +43,7 @@ type controllerServer struct {
4343 vscManager * internal.PrimaryVscManagerWithCache
4444 attachDetacher internal.CPFSAttachDetacher
4545 nasClient * nasclient.Client
46+ skipDetach bool
4647}
4748
4849func newControllerServer (region string ) (* controllerServer , error ) {
@@ -51,6 +52,11 @@ func newControllerServer(region string) (*controllerServer, error) {
5152 return nil , err
5253 }
5354
55+ skipDetach := false
56+ if skipDetachVal , _ := strconv .ParseBool (os .Getenv ("SKIP_BMCPFS_DETACH" )); skipDetachVal {
57+ skipDetach = skipDetachVal
58+ }
59+
5460 nasClient , err := cloud .NewNasClientV2 (region )
5561 if err != nil {
5662 return nil , err
@@ -59,6 +65,7 @@ func newControllerServer(region string) (*controllerServer, error) {
5965 vscManager : internal .NewPrimaryVscManagerWithCache (efloClient ),
6066 attachDetacher : internal .NewCPFSAttachDetacher (nasClient ),
6167 nasClient : nasClient ,
68+ skipDetach : skipDetach ,
6269 }, nil
6370}
6471
@@ -85,11 +92,12 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
8592 }, nil
8693 }
8794
95+ cpfsID , _ := parseVolumeHandle (req .VolumeId )
8896 // Get VscMountTarget of filesystem
8997 mt := req .VolumeContext [_vscMountTarget ]
9098 if mt == "" {
9199 var err error
92- mt , err = getMountTarget (cs .nasClient , req . VolumeId , networkTypeVSC )
100+ mt , err = getMountTarget (cs .nasClient , cpfsID , networkTypeVSC )
93101 if err != nil {
94102 return nil , status .Errorf (codes .Internal , "failed to get VscMountTarget: %v" , err )
95103 }
@@ -107,7 +115,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
107115 klog .Info ("Use VSC MountTarget for lingjun node" , "nodeId" , req .NodeId , "vscId" , vscId )
108116
109117 // Attach CPFS to VSC
110- err = cs .attachDetacher .Attach (ctx , req . VolumeId , vscId )
118+ err = cs .attachDetacher .Attach (ctx , cpfsID , vscId )
111119 if err != nil {
112120 if autoSwitch , _ := strconv .ParseBool (req .VolumeContext [_mpAutoSwitch ]); autoSwitch && internal .IsAttachNotSupportedError (err ) {
113121 if req .VolumeContext [_vpcMountTarget ] == "" {
@@ -138,10 +146,9 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
138146func (cs * controllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (
139147 * csi.ControllerUnpublishVolumeResponse , error ,
140148) {
141- if ! strings .HasPrefix (req .NodeId , LingjunNodeIDPrefix ) {
149+ if ! strings .HasPrefix (req .NodeId , LingjunNodeIDPrefix ) || cs . skipDetach {
142150 return & csi.ControllerUnpublishVolumeResponse {}, nil
143151 }
144-
145152 // Create Primary vsc for Lingjun node
146153 lingjunInstanceId := strings .TrimPrefix (req .NodeId , LingjunNodeIDPrefix )
147154 if LingjunNodeIDPrefix == "" {
@@ -155,6 +162,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
155162 klog .InfoS ("ControllerUnpublishVolume: skip detaching cpfs from vsc as vsc not found" , "node" , req .NodeId )
156163 return & csi.ControllerUnpublishVolumeResponse {}, nil
157164 }
165+ // If `req.VolumeId` is a combination of `cpfsID` and `fsetID`, Detach will trigger an error.
158166 err = cs .attachDetacher .Detach (ctx , req .VolumeId , vsc .VscID )
159167 if err != nil {
160168 return nil , status .Error (codes .Internal , err .Error ())
@@ -209,6 +217,14 @@ func newEfloClient(region string) (*efloclient.Client, error) {
209217 return efloclient .NewClient (config )
210218}
211219
220+ func parseVolumeHandle (volumeHandle string ) (string , string ) {
221+ parts := strings .Split (volumeHandle , volumeHandleDelimiter )
222+ if len (parts ) == 2 {
223+ return parts [0 ], parts [1 ]
224+ }
225+ return parts [0 ], ""
226+ }
227+
212228func getMountTarget (client * nasclient.Client , fsId , networkType string ) (string , error ) {
213229 resp , err := client .DescribeFileSystems (& nasclient.DescribeFileSystemsRequest {
214230 FileSystemId : & fsId ,
0 commit comments