-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: Delete Volume when creation fails with status ERROR #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
71b0721
e5c57fa
447c883
41378a3
87917aa
f05b4fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,6 +137,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||
| return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity") | ||||||||||||||
| } | ||||||||||||||
| if *vols[0].Status != stackitclient.VolumeAvailableStatus { | ||||||||||||||
| if cs.Driver.deleteVolumesInErrorState { | ||||||||||||||
| cs.deleteVolumeInError(ctx, &vols[0]) | ||||||||||||||
| } | ||||||||||||||
| return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", *vols[0].Id)) | ||||||||||||||
| } | ||||||||||||||
| klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", *vols[0].Id, vols[0].AvailabilityZone, *vols[0].Size) | ||||||||||||||
|
|
@@ -265,14 +268,14 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||
|
|
||||||||||||||
| targetStatus := []string{stackitclient.VolumeAvailableStatus} | ||||||||||||||
| // Recheck after: 0s (immediate), 20s, 45.6s, 78.36s, 120.31s | ||||||||||||||
| err = cloud.WaitVolumeTargetStatusWithCustomBackoff(ctx, *vol.Id, targetStatus, | ||||||||||||||
| err = cloud.WaitVolumeTargetStatusWithCustomBackoff(ctx, &vol, targetStatus, | ||||||||||||||
| &wait.Backoff{ | ||||||||||||||
| Duration: 20 * time.Second, | ||||||||||||||
| Steps: 5, | ||||||||||||||
| Factor: 1.28, | ||||||||||||||
| }) | ||||||||||||||
| if err != nil { | ||||||||||||||
| klog.Errorf("Failed to WaitVolumeTargetStatus of volume %s: %v", *vol.Id, err) | ||||||||||||||
| klog.Errorf("Failed to WaitVolumeTargetStatus of volume %s: %v", vol.GetId(), err) | ||||||||||||||
| return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume Volume %s failed getting available in time: %v", *vol.Id, err)) | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Rationale: Use |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -281,6 +284,18 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||
| return cs.getCreateVolumeResponse(vol), nil | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (cs *controllerServer) deleteVolumeInError(ctx context.Context, vol *iaas.Volume) { | ||||||||||||||
| cloud := cs.Instance | ||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Rationale: Add a defensive nil check on |
||||||||||||||
| if vol.GetStatus() == stackitclient.VolumeErrorStatus { | ||||||||||||||
| klog.Warningf("Volume %s entered ERROR status, attempting cleanup deletion...", vol.GetId()) | ||||||||||||||
| if deleteErr := cloud.DeleteVolume(ctx, vol.GetId()); deleteErr != nil { | ||||||||||||||
| klog.Errorf("Failed to delete erroneous volume %s: %v", vol.GetId(), deleteErr) | ||||||||||||||
| } else { | ||||||||||||||
| klog.Infof("Successfully deleted erroneous volume %s", vol.GetId()) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func setVolumeEncryptionParameters(opts *iaas.CreateVolumePayload, volParams *stackitParameterConfig) error { | ||||||||||||||
| err := validateEncryptionConfig(volParams) | ||||||||||||||
| if err != nil { | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationale: Use getter methods
GetStatus()andGetId()(orstatus.Errorf) to safely prevent potential nil pointer dereferences when inspectingvols[0].