Skip to content

Commit 01335c7

Browse files
committed
Delete bucket if annotation exist, add finalizer only if not deleting, create if not exist & no err
1 parent d6959bf commit 01335c7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

controllers/bucket_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
)
2121

2222
const (
23-
oadpFinalizerBucket = "oadp.openshift.io/bucket-protection"
23+
oadpFinalizerBucket = "oadp.openshift.io/bucket-protection"
24+
oadpCloudStorageDeleteAnnotation = "oadp.openshift.io/cloudstorage-delete"
2425
)
2526

2627
// VeleroReconciler reconciles a Velero object
@@ -60,8 +61,8 @@ func (b BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
6061
return result, nil
6162
}
6263

63-
// Add finalizer if none exists.
64-
if !containFinalizer(bucket.Finalizers, oadpFinalizerBucket) {
64+
// Add finalizer if none exists and object is not being deleted.
65+
if bucket.DeletionTimestamp == nil && !containFinalizer(bucket.Finalizers, oadpFinalizerBucket) {
6566
bucket.Finalizers = append(bucket.Finalizers, oadpFinalizerBucket)
6667
err := b.Client.Update(ctx, &bucket, &client.UpdateOptions{})
6768
if err != nil {
@@ -75,8 +76,7 @@ func (b BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
7576
if err != nil {
7677
return result, err
7778
}
78-
79-
if bucket.DeletionTimestamp != nil {
79+
if bucket.Annotations[oadpCloudStorageDeleteAnnotation] == "true" && bucket.DeletionTimestamp != nil {
8080
deleted, err := clnt.Delete()
8181
if err != nil {
8282
log.Error(err, "unable to delete bucket")
@@ -107,8 +107,8 @@ func (b BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
107107
return ctrl.Result{Requeue: true}, nil
108108
}
109109
var ok bool
110-
if ok, err = clnt.Exists(); !ok {
111-
// Handle Deletion.
110+
if ok, err = clnt.Exists(); !ok && err == nil {
111+
// Handle Creation if not exist.
112112
created, err := clnt.Create()
113113
if !created {
114114
log.Info("unable to create object bucket")

0 commit comments

Comments
 (0)