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>
This commit is contained in:
parent
07a539e3d6
commit
f72a28a193
|
@ -96,6 +96,7 @@ type BucketReconciler struct {
|
|||
helper.Metrics
|
||||
|
||||
Storage *Storage
|
||||
ControllerName string
|
||||
}
|
||||
|
||||
type BucketReconcilerOptions struct {
|
||||
|
@ -160,6 +161,7 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
|
|||
summarize.RecordReconcileReq,
|
||||
),
|
||||
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
|
||||
summarize.WithPatchFieldOwner(r.ControllerName),
|
||||
}
|
||||
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ type GitRepositoryReconciler struct {
|
|||
helper.Metrics
|
||||
|
||||
Storage *Storage
|
||||
ControllerName string
|
||||
|
||||
requeueDependency time.Duration
|
||||
}
|
||||
|
@ -166,6 +167,7 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|||
summarize.RecordReconcileReq,
|
||||
),
|
||||
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
|
||||
summarize.WithPatchFieldOwner(r.ControllerName),
|
||||
}
|
||||
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ type HelmChartReconciler struct {
|
|||
|
||||
Storage *Storage
|
||||
Getters helmgetter.Providers
|
||||
ControllerName string
|
||||
}
|
||||
|
||||
func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
|
@ -191,6 +192,7 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
|||
summarize.RecordReconcileReq,
|
||||
),
|
||||
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
|
||||
summarize.WithPatchFieldOwner(r.ControllerName),
|
||||
}
|
||||
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ type HelmRepositoryReconciler struct {
|
|||
|
||||
Getters helmgetter.Providers
|
||||
Storage *Storage
|
||||
ControllerName string
|
||||
}
|
||||
|
||||
type HelmRepositoryReconcilerOptions struct {
|
||||
|
@ -153,6 +154,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
|||
summarize.RecordReconcileReq,
|
||||
),
|
||||
summarize.WithResultBuilder(sreconcile.AlwaysRequeueResultBuilder{RequeueAfter: obj.GetInterval().Duration}),
|
||||
summarize.WithPatchFieldOwner(r.ControllerName),
|
||||
}
|
||||
result, retErr = summarizeHelper.SummarizeAndPatch(ctx, obj, summarizeOpts...)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
4
main.go
4
main.go
|
@ -169,6 +169,7 @@ func main() {
|
|||
EventRecorder: eventRecorder,
|
||||
Metrics: metricsH,
|
||||
Storage: storage,
|
||||
ControllerName: controllerName,
|
||||
}).SetupWithManagerAndOptions(mgr, controllers.GitRepositoryReconcilerOptions{
|
||||
MaxConcurrentReconciles: concurrent,
|
||||
DependencyRequeueInterval: requeueDependency,
|
||||
|
@ -182,6 +183,7 @@ func main() {
|
|||
Metrics: metricsH,
|
||||
Storage: storage,
|
||||
Getters: getters,
|
||||
ControllerName: controllerName,
|
||||
}).SetupWithManagerAndOptions(mgr, controllers.HelmRepositoryReconcilerOptions{
|
||||
MaxConcurrentReconciles: concurrent,
|
||||
}); err != nil {
|
||||
|
@ -194,6 +196,7 @@ func main() {
|
|||
Getters: getters,
|
||||
EventRecorder: eventRecorder,
|
||||
Metrics: metricsH,
|
||||
ControllerName: controllerName,
|
||||
}).SetupWithManagerAndOptions(mgr, controllers.HelmChartReconcilerOptions{
|
||||
MaxConcurrentReconciles: concurrent,
|
||||
}); err != nil {
|
||||
|
@ -205,6 +208,7 @@ func main() {
|
|||
EventRecorder: eventRecorder,
|
||||
Metrics: metricsH,
|
||||
Storage: storage,
|
||||
ControllerName: controllerName,
|
||||
}).SetupWithManagerAndOptions(mgr, controllers.BucketReconcilerOptions{
|
||||
MaxConcurrentReconciles: concurrent,
|
||||
}); err != nil {
|
||||
|
|
Loading…
Reference in New Issue