Skip to content
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

[release-4.4] Bug 1820584: OpenStack: Add retries to DeleteGlanceImage #3407

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 31 additions & 5 deletions pkg/destroy/openstack/glance.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
package openstack

import (
"time"

"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/utils/openstack/clientconfig"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"k8s.io/apimachinery/pkg/util/wait"
)

// DeleteGlanceImage deletes the image with the specified name
func DeleteGlanceImage(name string, cloud string) error {
backoffSettings := wait.Backoff{
Duration: time.Second * 20,
Steps: 30,
}

err := wait.ExponentialBackoff(backoffSettings, func() (bool, error) {
return deleteGlanceImage(name, cloud)
})
if err != nil {
return errors.Errorf("Unrecoverable error/timed out: %v", err)
}

return nil
}

func deleteGlanceImage(name string, cloud string) (bool, error) {
opts := clientconfig.ClientOpts{
Cloud: cloud,
}

conn, err := clientconfig.NewServiceClient("image", &opts)
if err != nil {
return err
logrus.Warningf("There was an error during the image removal: %v", err)
return false, nil
}

listOpts := images.ListOpts{
Expand All @@ -22,19 +45,22 @@ func DeleteGlanceImage(name string, cloud string) error {

allPages, err := images.List(conn, listOpts).AllPages()
if err != nil {
return err
logrus.Warningf("There was an error during the image removal: %v", err)
return false, nil
}

allImages, err := images.ExtractImages(allPages)
if err != nil {
return err
logrus.Warningf("There was an error during the image removal: %v", err)
return false, nil
}

for _, image := range allImages {
err := images.Delete(conn, image.ID).ExtractErr()
if err != nil {
return err
logrus.Warningf("There was an error during the image removal: %v", err)
return false, nil
}
}
return nil
return true, nil
}