@@ -1100,6 +1100,13 @@ func (c *controller) ControllerUnpublishVolume(ctx context.Context, req *csi.Con
11001100 return resp , err
11011101}
11021102
1103+ // `:detaching` suffix is added by VM Operator to the volume name in the VM status
1104+ // that is in the process of being detached.
1105+ // removeDetachingSuffixFromVolumeName removes the suffix from the volume name.
1106+ func removeDetachingSuffixFromVolumeName (volumeName string ) string {
1107+ return strings .TrimSuffix (volumeName , ":detaching" )
1108+ }
1109+
11031110// controllerUnpublishForBlockVolume is helper method to handle ControllerPublishVolume for Block volumes
11041111func controllerUnpublishForBlockVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest , c * controller ) (
11051112 * csi.ControllerUnpublishVolumeResponse , string , error ) {
@@ -1150,7 +1157,8 @@ func controllerUnpublishForBlockVolume(ctx context.Context, req *csi.ControllerU
11501157 }
11511158 isVolumePresentInVMStatus := false
11521159 for _ , volume := range virtualMachine .Status .Volumes {
1153- if volume .Name == req .VolumeId {
1160+ name := removeDetachingSuffixFromVolumeName (volume .Name )
1161+ if name == req .VolumeId {
11541162 isVolumePresentInVMStatus = true
11551163 }
11561164 }
@@ -1197,7 +1205,8 @@ func controllerUnpublishForBlockVolume(ctx context.Context, req *csi.ControllerU
11971205 case watch .Added , watch .Modified :
11981206 isVolumeDetached = true
11991207 for _ , volume := range vm .Status .Volumes {
1200- if volume .Name == req .VolumeId {
1208+ name := removeDetachingSuffixFromVolumeName (volume .Name )
1209+ if name == req .VolumeId {
12011210 log .Debugf ("Volume %q still exists in VirtualMachine %q status" , volume .Name , virtualMachine .Name )
12021211 isVolumeDetached = false
12031212 if volume .Attached && volume .Error != "" {
0 commit comments