From 22832fd4b58fa0209f4964dff56a1ac12bb362bb Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 21 Feb 2022 15:38:28 +0530 Subject: [PATCH] Use field owner in the patch helper - Update summarize helper to have patch field owner. - Updated the controllers to set the patch field owner. Signed-off-by: Sunny --- controllers/bucket_controller.go | 1 + controllers/gitrepository_controller.go | 1 + controllers/helmchart_controller.go | 1 + controllers/helmrepository_controller.go | 1 + internal/reconcile/summarize/summary.go | 13 +++++++++++++ 5 files changed, 17 insertions(+) diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index 54bf8e51a..26a8e71fb 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -160,6 +160,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res summarize.RecordReconcileReq, ), summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}), + summarize.WithPatchFieldOwner("source-controller"), } result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index bea7531d3..713f0b86b 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -165,6 +165,7 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques summarize.RecordReconcileReq, ), summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}), + summarize.WithPatchFieldOwner("source-controller"), } result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...) diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index f921fe9a8..7e5227ea2 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -191,6 +191,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( summarize.RecordReconcileReq, ), summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}), + summarize.WithPatchFieldOwner("source-controller"), } result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...) diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index 39b28e984..4f4c44f89 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -153,6 +153,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque summarize.RecordReconcileReq, ), summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}), + summarize.WithPatchFieldOwner("source-controller"), } result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...) diff --git a/internal/reconcile/summarize/summary.go b/internal/reconcile/summarize/summary.go index 0ba76715f..1c2f97aae 100644 --- a/internal/reconcile/summarize/summary.go +++ b/internal/reconcile/summarize/summary.go @@ -85,6 +85,9 @@ type HelperOptions struct { ReconcileError error // ResultBuilder defines how the reconciliation result is computed. ResultBuilder reconcile.RuntimeResultBuilder + // PatchFieldOwner defines the field owner configuration for the Kubernetes + // patch operation. + PatchFieldOwner string } // Option is configuration that modifies SummarizeAndPatch. @@ -137,6 +140,13 @@ func WithReconcileError(re error) Option { } } +// WithPatchFieldOwner sets the FieldOwner in the patch helper. +func WithPatchFieldOwner(fieldOwner string) Option { + return func(s *HelperOptions) { + s.PatchFieldOwner = fieldOwner + } +} + // SummarizeAndPatch summarizes and patches the result to the target object. // When used at the very end of a reconciliation, the result builder must be // specified using the Option WithResultBuilder(). The returned result and error @@ -161,6 +171,9 @@ func (h *Helper) SummarizeAndPatch(ctx context.Context, obj conditions.Setter, o Conditions: ownedConditions, }, } + if opts.PatchFieldOwner != "" { + patchOpts = append(patchOpts, patch.WithFieldOwner(opts.PatchFieldOwner)) + } // Process the results of reconciliation. for _, processor := range opts.Processors {