github.com/openshift/installer@v1.4.17/pkg/destroy/gcp/bucketobject.go (about) 1 package gcp 2 3 import ( 4 "context" 5 6 "github.com/pkg/errors" 7 storage "google.golang.org/api/storage/v1" 8 ) 9 10 func (o *ClusterUninstaller) listBucketObjects(ctx context.Context, bucket cloudResource) ([]cloudResource, error) { 11 o.Logger.Debugf("Listing objects for storage bucket %s", bucket.name) 12 ctx, cancel := context.WithTimeout(ctx, defaultTimeout) 13 defer cancel() 14 result := []cloudResource{} 15 req := o.storageSvc.Objects.List(bucket.name).Fields("items(name),nextPageToken") 16 err := req.Pages(ctx, func(objects *storage.Objects) error { 17 for _, object := range objects.Items { 18 o.Logger.Debugf("Found storage object %s/%s", bucket.name, object.Name) 19 result = append(result, cloudResource{ 20 key: object.Name, 21 name: object.Name, 22 typeName: "bucketobject", 23 }) 24 } 25 return nil 26 }) 27 if err != nil { 28 return nil, errors.Wrapf(err, "failed to fetch objects for bucket %s", bucket.name) 29 } 30 return result, nil 31 } 32 33 func (o *ClusterUninstaller) deleteBucketObject(ctx context.Context, bucket cloudResource, item cloudResource) error { 34 o.Logger.Debugf("Deleting storage object %s/%s", bucket.name, item.name) 35 ctx, cancel := context.WithTimeout(ctx, defaultTimeout) 36 defer cancel() 37 err := o.storageSvc.Objects.Delete(bucket.name, item.name).Context(ctx).Do() 38 if err != nil && !isNoOp(err) { 39 return errors.Wrapf(err, "failed to delete bucket object %s/%s", bucket.name, item.name) 40 } 41 o.deletePendingItems(item.typeName, []cloudResource{item}) 42 o.Logger.Infof("Deleted bucket object %s", item.name) 43 return nil 44 }