Skip to content

Commit

Permalink
resource: use Patch in APIFinalizer
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
  • Loading branch information
sttts committed Sep 18, 2023
1 parent 2ad600c commit 6fe554e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/resource/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,19 @@ 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.
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.
Expand Down

0 comments on commit 6fe554e

Please sign in to comment.