Skip to content

Commit 495d1ff

Browse files
authored
Fix incorrect virtual machine watch logic in volume unpublish logic in guest cluster (#3782)
1 parent b28f50c commit 495d1ff

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/csi/service/wcpguest/controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
11041111
func 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

Comments
 (0)