From 048e5178123a11ebb9be45d9bb0ad9ef7bb9250e Mon Sep 17 00:00:00 2001 From: Ben Moss Date: Thu, 24 Jun 2021 11:51:52 -0400 Subject: [PATCH] Add ability to filter objects on injection controller promotion Currently we enqueue every object with no way to filter, which causes problems for eventing's source controller which reconciles duck CRDs. --- .../injection-gen/generators/reconciler_controller.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/codegen/cmd/injection-gen/generators/reconciler_controller.go b/codegen/cmd/injection-gen/generators/reconciler_controller.go index 9471b5db8a..c97f8108dd 100644 --- a/codegen/cmd/injection-gen/generators/reconciler_controller.go +++ b/codegen/cmd/injection-gen/generators/reconciler_controller.go @@ -217,6 +217,8 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu lister := {{.type|lowercaseSingular}}Informer.Lister() + var promoteFilterFunc func(obj interface{}) bool + rec := &reconcilerImpl{ LeaderAwareFuncs: {{.reconcilerLeaderAwareFuncs|raw}}{ PromoteFunc: func(bkt {{.reconcilerBucket|raw}}, enq func({{.reconcilerBucket|raw}}, {{.typesNamespacedName|raw}})) error { @@ -225,7 +227,11 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu return err } for _, elt := range all { - // TODO: Consider letting users specify a filter in options. + if promoteFilterFunc != nil { + if ok := promoteFilterFunc(elt); !ok { + continue + } + } enq(bkt, {{.typesNamespacedName|raw}}{ Namespace: elt.GetNamespace(), Name: elt.GetName(), @@ -274,6 +280,9 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu if opts.DemoteFunc != nil { rec.DemoteFunc = opts.DemoteFunc } + if opts.PromoteFilterFunc != nil { + promoteFilterFunc = opts.PromoteFilterFunc + } } rec.Recorder = createRecorder(ctx, agentName)