-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bug 2047732: [IBM]Volume is not deleted after destroy cluster #5962
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| package ibmcloud | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| func (o *ClusterUninstaller) listDisks() ([]cloudResource, error) { | ||
| o.Logger.Infof("Listing disks") | ||
|
|
||
| result := []cloudResource{} | ||
| clusterOwnedTag := o.clusterLabelFilter() | ||
| options := o.vpcSvc.NewListVolumesOptions() | ||
|
|
||
| for { | ||
| ctx, cancel := o.contextWithTimeout() | ||
| defer cancel() | ||
| options.SetLimit(100) | ||
| resources, _, err := o.vpcSvc.ListVolumesWithContext(ctx, options) | ||
| if err != nil { | ||
sameshai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil, errors.Wrap(err, "Listing disks failed") | ||
| } | ||
|
|
||
| for _, volume := range resources.Volumes { | ||
| userTags := strings.Join(volume.UserTags, ",") | ||
| if strings.Contains(userTags, clusterOwnedTag) { | ||
| o.Logger.Debugf("Found disk: %s", *volume.ID) | ||
| result = append(result, cloudResource{ | ||
| key: *volume.ID, | ||
| name: *volume.Name, | ||
| status: *volume.Status, | ||
| typeName: "disk", | ||
| id: *volume.ID, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| //This was the last page, please exit the loop. | ||
| if resources.Next == nil { | ||
| o.Logger.Debugf("All disks fetched") | ||
| break | ||
| } | ||
|
|
||
| //Set the start for the next page. | ||
| start, _ := resources.GetNextStart() | ||
| o.Logger.Debugf("Listing next page %s", *start) | ||
| options.SetStart(*start) | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) deleteDisk(item cloudResource) error { | ||
| o.Logger.Infof("Deleting disk %s", item.id) | ||
| ctx, cancel := o.contextWithTimeout() | ||
| defer cancel() | ||
| options := o.vpcSvc.NewDeleteVolumeOptions(item.id) | ||
| details, err := o.vpcSvc.DeleteVolumeWithContext(ctx, options) | ||
|
|
||
| if err != nil && details.StatusCode != http.StatusNotFound { | ||
| return errors.Wrapf(err, "Failed to delete disk name=%s, id=%s.If this error continues to persist for more than 20 minutes then please try to manually cleanup the volume using - ibmcloud is vold %s", item.name, item.id, item.id) | ||
| } | ||
|
|
||
| if err != nil && details.StatusCode == http.StatusNotFound { | ||
| // The resource is gone | ||
| o.deletePendingItems(item.typeName, []cloudResource{item}) | ||
| o.Logger.Infof("Deleted disk %s", item.id) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (o *ClusterUninstaller) waitForDiskDeletion(item cloudResource) error { | ||
| o.Logger.Infof("Waiting for disk %s to be deleted", item.id) | ||
| var skip = false | ||
|
|
||
| err := o.Retry(func() (error, bool) { | ||
| ctx, cancel := o.contextWithTimeout() | ||
| defer cancel() | ||
| volumeOptions := o.vpcSvc.NewGetVolumeOptions(item.id) | ||
| _, response, err := o.vpcSvc.GetVolumeWithContext(ctx, volumeOptions) | ||
| // Keep retry, until GetVolume returns volume not found | ||
| if err != nil && response.StatusCode == http.StatusNotFound { | ||
| skip = true | ||
| return nil, skip | ||
| } | ||
| return err, false // continue retry as we are not seeing error which means volume is available | ||
| }) | ||
|
|
||
| if err == nil && skip { | ||
| // The resource is gone | ||
| o.deletePendingItems(item.typeName, []cloudResource{item}) | ||
| o.Logger.Infof("Deleted disk %s", item.id) | ||
| } else { | ||
| return errors.Wrapf(err, "Failed to delete disk name=%s, id=%s.If this error continues to persist for more than 20 minutes then please try to manually cleanup the volume using - ibmcloud is vold %s", item.name, item.id, item.id) | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| // destroyDisks removes all disk resources that have a name prefixed | ||
| // with the cluster's infra ID. | ||
| func (o *ClusterUninstaller) destroyDisks() error { | ||
| found, err := o.listDisks() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| items := o.insertPendingItems("disk", found) | ||
sameshai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for _, item := range items { | ||
| err := o.deleteDisk(item) | ||
| if err != nil { | ||
| o.errorTracker.suppressWarning(item.key, err, o.Logger) | ||
| } | ||
| } | ||
|
|
||
| for _, item := range items { | ||
| err := o.waitForDiskDeletion(item) | ||
| if err != nil { | ||
| o.errorTracker.suppressWarning(item.key, err, o.Logger) | ||
| } | ||
| } | ||
|
|
||
| if items = o.getPendingItems("disk"); len(items) > 0 { | ||
| return errors.Errorf("%d items pending", len(items)) | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.