Skip to content

Commit

Permalink
Bug 1816155: Add retries to DeleteGlanceImage
Browse files Browse the repository at this point in the history
Now if the function fails, we stop the installation immediately,
but it's better to retry several times before finally stopping the
installation.
  • Loading branch information
Fedosin committed Mar 26, 2020
1 parent de1aaf8 commit bc264a6
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions pkg/destroy/openstack/glance.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
package openstack

import (
"time"

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

"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
return false, err
}

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

allPages, err := images.List(conn, listOpts).AllPages()
if err != nil {
return err
return false, err
}

allImages, err := images.ExtractImages(allPages)
if err != nil {
return err
return false, err
}

for _, image := range allImages {
err := images.Delete(conn, image.ID).ExtractErr()
if err != nil {
return err
return false, err
}
}
return nil
return true, nil
}

0 comments on commit bc264a6

Please sign in to comment.