Skip to content

Commit 21a772f

Browse files
committed
bucket: Ignore patch error not found on delete
Ignore "not found" error while patching when the delete timestamp is set. Signed-off-by: Sunny <[email protected]>
1 parent ea18a4e commit 21a772f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

controllers/bucket_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"golang.org/x/sync/semaphore"
3636
"google.golang.org/api/option"
3737
corev1 "k8s.io/api/core/v1"
38+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3839
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3940
"k8s.io/apimachinery/pkg/types"
4041
kerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -167,6 +168,10 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
167168

168169
// Finally, patch the resource
169170
if err := patchHelper.Patch(ctx, obj, patchOpts...); err != nil {
171+
// Ignore patch error "not found" when the object is being deleted.
172+
if !obj.ObjectMeta.DeletionTimestamp.IsZero() {
173+
err = kerrors.FilterOut(err, func(e error) bool { return apierrors.IsNotFound(e) })
174+
}
170175
retErr = kerrors.NewAggregate([]error{retErr, err})
171176
}
172177

0 commit comments

Comments
 (0)