Skip to content

Commit 1e0a726

Browse files
committed
fix detatch volume logic
1 parent 2fc6761 commit 1e0a726

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pkg/stackit/client/iaas.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,23 @@ func (i iaasClient) DetachVolume(ctx context.Context, serverID, volumeID string)
503503
return err
504504
}
505505

506-
if *volume.Status != VolumeAvailableStatus {
506+
if *volume.Status == VolumeAvailableStatus {
507+
klog.V(2).Infof("Volume: %s has been detached from compute: %s ", *volume.Id, serverID)
508+
return nil
509+
}
510+
511+
if *volume.Status != VolumeAttachedStatus {
507512
return fmt.Errorf("can not detach volume %s, its status is %s", *volume.Name, *volume.Status)
508513
}
509514

510-
return i.Client.RemoveVolumeFromServer(ctx, i.projectID, i.region, serverID, volumeID).Execute()
515+
if volume.ServerId != nil && *volume.ServerId == serverID {
516+
if err := i.Client.RemoveVolumeFromServer(ctx, i.projectID, i.region, serverID, volumeID).Execute(); err != nil {
517+
return fmt.Errorf("failed to detach volume %s from compute %s : %w", *volume.Name, serverID, err)
518+
}
519+
klog.V(2).Infof("Successfully detached volume: %s from compute: %s", *volume.Id, serverID)
520+
}
521+
522+
return nil
511523
}
512524

513525
func (i iaasClient) WaitVolumeTargetStatusWithCustomBackoff(ctx context.Context, volumeID string, tStatus []string, backoff *wait.Backoff) error {

0 commit comments

Comments
 (0)