Skip to content

Commit

Permalink
Use field owner in the patch helper
Browse files Browse the repository at this point in the history
- Update summarize helper to have patch field owner.
- Updated the controllers to set the patch field owner.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Feb 21, 2022
1 parent eff68c8 commit 22832fd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
1 change: 1 addition & 0 deletions controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
1 change: 1 addition & 0 deletions controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
1 change: 1 addition & 0 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
13 changes: 13 additions & 0 deletions internal/reconcile/summarize/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 22832fd

Please sign in to comment.