From 6fe554e18d4d1a7d7ecb61da64437130b961945a Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 18 Sep 2023 22:27:37 +0300 Subject: [PATCH] resource: use Patch in APIFinalizer Signed-off-by: Dr. Stefan Schimanski --- pkg/resource/api.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/resource/api.go b/pkg/resource/api.go index 8c60dd3e4..03621108b 100644 --- a/pkg/resource/api.go +++ b/pkg/resource/api.go @@ -161,8 +161,9 @@ func (a *APIFinalizer) AddFinalizer(ctx context.Context, obj Object) error { if meta.FinalizerExists(obj, a.finalizer) { return nil } + orig := obj.DeepCopyObject().(Object) meta.AddFinalizer(obj, a.finalizer) - return errors.Wrap(a.client.Update(ctx, obj), errUpdateObject) + return errors.Wrap(a.client.Patch(ctx, obj, client.MergeFromWithOptions(orig, client.MergeFromWithOptimisticLock{})), errUpdateObject) } // RemoveFinalizer from the supplied Managed resource. @@ -170,8 +171,9 @@ func (a *APIFinalizer) RemoveFinalizer(ctx context.Context, obj Object) error { if !meta.FinalizerExists(obj, a.finalizer) { return nil } + orig := obj.DeepCopyObject().(Object) meta.RemoveFinalizer(obj, a.finalizer) - return errors.Wrap(IgnoreNotFound(a.client.Update(ctx, obj)), errUpdateObject) + return errors.Wrap(IgnoreNotFound(a.client.Patch(ctx, obj, client.MergeFromWithOptions(orig, client.MergeFromWithOptimisticLock{}))), errUpdateObject) } // A FinalizerFns satisfy the Finalizer interface.