From 826ac78c90ea807ccca6920140db9c326e12a66f Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Thu, 18 Jul 2024 19:29:36 +0200 Subject: [PATCH] refactor: simplify SSA patch calls Signed-off-by: Erik Godding Boye --- pkg/bundle/bundle.go | 8 +------- pkg/bundle/target.go | 10 ++-------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/bundle/bundle.go b/pkg/bundle/bundle.go index 3f768e23..0f06f87d 100644 --- a/pkg/bundle/bundle.go +++ b/pkg/bundle/bundle.go @@ -33,7 +33,6 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/client-go/util/csaupgrade" "k8s.io/utils/clock" - "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -103,12 +102,7 @@ func (b *bundle) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, return ctrl.Result{}, utilerrors.NewAggregate([]error{resultErr, err}) } - if err := b.client.Status().Patch(ctx, con, patch, &client.SubResourcePatchOptions{ - PatchOptions: client.PatchOptions{ - FieldManager: fieldManager, - Force: ptr.To(true), - }, - }); err != nil { + if err := b.client.Status().Patch(ctx, con, patch, client.FieldOwner(fieldManager), client.ForceOwnership); err != nil { err = fmt.Errorf("failed to apply bundle status patch: %w", err) return ctrl.Result{}, utilerrors.NewAggregate([]error{resultErr, err}) } diff --git a/pkg/bundle/target.go b/pkg/bundle/target.go index e9532167..0d890b34 100644 --- a/pkg/bundle/target.go +++ b/pkg/bundle/target.go @@ -370,10 +370,7 @@ func (b *bundle) patchConfigMapResource(ctx context.Context, applyConfig *coreap return fmt.Errorf("failed to generate patch: %w", err) } - err = b.client.Patch(ctx, configMap, patch, &client.PatchOptions{ - FieldManager: fieldManager, - Force: ptr.To(true), - }) + err = b.client.Patch(ctx, configMap, patch, client.FieldOwner(fieldManager), client.ForceOwnership) if err != nil { return err } @@ -396,10 +393,7 @@ func (b *bundle) patchSecretResource(ctx context.Context, applyConfig *coreapply return fmt.Errorf("failed to generate patch: %w", err) } - err = b.client.Patch(ctx, secret, patch, &client.PatchOptions{ - FieldManager: fieldManager, - Force: ptr.To(true), - }) + err = b.client.Patch(ctx, secret, patch, client.FieldOwner(fieldManager), client.ForceOwnership) if err != nil { return err }