From 3683d96136a52d06274788006e0c5c67d9818c93 Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Thu, 13 Jun 2024 19:00:20 +0300 Subject: [PATCH] feat: wait volume to be detached Proxmox delays the volume detach operation sometimes. This commit adds a wait loop to wait for the volume to be detached. Signed-off-by: Serge Logvinov --- pkg/csi/utils.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/csi/utils.go b/pkg/csi/utils.go index 7767ab3..7634bf8 100644 --- a/pkg/csi/utils.go +++ b/pkg/csi/utils.go @@ -188,8 +188,24 @@ func waitForVolumeAttach(cl *pxapi.Client, vmr *pxapi.VmRef, lun int) error { return fmt.Errorf("timeout waiting for disk to attach") } -func waitForVolumeDetach(_ *pxapi.Client, _ *pxapi.VmRef, _ int) error { - return nil +func waitForVolumeDetach(cl *pxapi.Client, vmr *pxapi.VmRef, lun int) error { + waited := 0 + for waited < TaskTimeout { + config, err := cl.GetVmConfig(vmr) + if err != nil { + return fmt.Errorf("failed to get vm config: %v", err) + } + + device := fmt.Sprintf("%s%d", deviceNamePrefix, lun) + if config[device] == nil { + return nil + } + + time.Sleep(TaskStatusCheckInterval * time.Second) + waited += TaskStatusCheckInterval + } + + return fmt.Errorf("timeout waiting for disk to detach") } func createVolume(cl *pxapi.Client, vol *volume.Volume, sizeGB int) error {