Skip to content

Commit 22832fd

Browse files
committed
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 <darkowlzz@protonmail.com>
1 parent eff68c8 commit 22832fd

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

controllers/bucket_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
160160
summarize.RecordReconcileReq,
161161
),
162162
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
163+
summarize.WithPatchFieldOwner("source-controller"),
163164
}
164165
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
165166

controllers/gitrepository_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
165165
summarize.RecordReconcileReq,
166166
),
167167
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
168+
summarize.WithPatchFieldOwner("source-controller"),
168169
}
169170
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
170171

controllers/helmchart_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
191191
summarize.RecordReconcileReq,
192192
),
193193
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
194+
summarize.WithPatchFieldOwner("source-controller"),
194195
}
195196
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
196197

controllers/helmrepository_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
153153
summarize.RecordReconcileReq,
154154
),
155155
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
156+
summarize.WithPatchFieldOwner("source-controller"),
156157
}
157158
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
158159

internal/reconcile/summarize/summary.go

+13
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type HelperOptions struct {
8585
ReconcileError error
8686
// ResultBuilder defines how the reconciliation result is computed.
8787
ResultBuilder reconcile.RuntimeResultBuilder
88+
// PatchFieldOwner defines the field owner configuration for the Kubernetes
89+
// patch operation.
90+
PatchFieldOwner string
8891
}
8992

9093
// Option is configuration that modifies SummarizeAndPatch.
@@ -137,6 +140,13 @@ func WithReconcileError(re error) Option {
137140
}
138141
}
139142

143+
// WithPatchFieldOwner sets the FieldOwner in the patch helper.
144+
func WithPatchFieldOwner(fieldOwner string) Option {
145+
return func(s *HelperOptions) {
146+
s.PatchFieldOwner = fieldOwner
147+
}
148+
}
149+
140150
// SummarizeAndPatch summarizes and patches the result to the target object.
141151
// When used at the very end of a reconciliation, the result builder must be
142152
// 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
161171
Conditions: ownedConditions,
162172
},
163173
}
174+
if opts.PatchFieldOwner != "" {
175+
patchOpts = append(patchOpts, patch.WithFieldOwner(opts.PatchFieldOwner))
176+
}
164177

165178
// Process the results of reconciliation.
166179
for _, processor := range opts.Processors {

0 commit comments

Comments
 (0)