Skip to content

Commit

Permalink
feat: wait volume to be detached
Browse files Browse the repository at this point in the history
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 <serge.logvinov@sinextra.dev>
  • Loading branch information
sergelogvinov committed Jun 13, 2024
1 parent 79eb881 commit 3683d96
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/csi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3683d96

Please sign in to comment.