diff --git a/codegen/cmd/injection-gen/generators/reconciler_controller.go b/codegen/cmd/injection-gen/generators/reconciler_controller.go index a41e3a1e20..da2b6f4a8a 100644 --- a/codegen/cmd/injection-gen/generators/reconciler_controller.go +++ b/codegen/cmd/injection-gen/generators/reconciler_controller.go @@ -164,7 +164,7 @@ const ( // the queue through an implementation of {{.controllerReconciler|raw}}, delegating to // the provided Interface and optional Finalizer methods. OptionsFn is used to return // {{.controllerOptions|raw}} to be used but the internal reconciler. -func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValue string{{end}}, optionsFns ...{{.controllerOptionsFn|raw}}) *{{.controllerImpl|raw}} { +func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classFilter func(interface{}) bool{{end}}, optionsFns ...{{.controllerOptionsFn|raw}}) *{{.controllerImpl|raw}} { logger := {{.loggingFromContext|raw}}(ctx) // Check the options function input. It should be 0 or 1. @@ -198,7 +198,7 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu Lister: {{.type|lowercaseSingular}}Informer.Lister(), Recorder: recorder, reconciler: r, - {{if .hasClass}}classValue: classValue,{{end}} + {{if .hasClass}}classFilter: classFilter,{{end}} } impl := {{.controllerNewImpl|raw}}(rec, logger, defaultQueueName) diff --git a/codegen/cmd/injection-gen/generators/reconciler_controller_stub.go b/codegen/cmd/injection-gen/generators/reconciler_controller_stub.go index 4c745e43fd..6e64583409 100644 --- a/codegen/cmd/injection-gen/generators/reconciler_controller_stub.go +++ b/codegen/cmd/injection-gen/generators/reconciler_controller_stub.go @@ -120,14 +120,15 @@ func NewController( {{if .hasClass}} classValue := "default" // TODO: update this to the appropriate value. - classFilter := {{.annotationFilterFunc|raw}}({{.classAnnotationKey|raw}}, classValue, false /*allowUnset*/) + allowUnset := false // TODO: update this to specific matching unset ClassAnnotationKey or not. + classFilter := {{.annotationFilterFunc|raw}}({{.classAnnotationKey|raw}}, classValue, allowUnset /*allowUnset*/) {{end}} // TODO: setup additional informers here. {{if .hasClass}}// TODO: remember to use the classFilter from above to filter appropriately.{{end}} r := &Reconciler{} - impl := {{.reconcilerNewImpl|raw}}(ctx, r{{if .hasClass}}, classValue{{end}}) + impl := {{.reconcilerNewImpl|raw}}(ctx, r{{if .hasClass}}, classFilter{{end}}) logger.Info("Setting up event handlers.") diff --git a/codegen/cmd/injection-gen/generators/reconciler_reconciler.go b/codegen/cmd/injection-gen/generators/reconciler_reconciler.go index c3e08bdbf3..a434f971a8 100644 --- a/codegen/cmd/injection-gen/generators/reconciler_reconciler.go +++ b/codegen/cmd/injection-gen/generators/reconciler_reconciler.go @@ -198,8 +198,8 @@ type reconcilerImpl struct { reconciler Interface {{if .hasClass}} - // classValue is the resource annotation[{{ .class }}] instance value this reconciler instance filters on. - classValue string + // classFilter is the filter function for annotation[eventing.knative.dev/broker.class] instance value this reconciler instance filters on. + classFilter func(interface{}) bool {{end}} } @@ -209,7 +209,7 @@ var _ controller.Reconciler = (*reconcilerImpl)(nil) ` var reconcilerNewReconciler = ` -func NewReconciler(ctx {{.contextContext|raw}}, logger *{{.zapSugaredLogger|raw}}, client {{.clientsetInterface|raw}}, lister {{.resourceLister|raw}}, recorder {{.recordEventRecorder|raw}}, r Interface{{if .hasClass}}, classValue string{{end}}, options ...{{.controllerOptions|raw}} ) {{.controllerReconciler|raw}} { +func NewReconciler(ctx {{.contextContext|raw}}, logger *{{.zapSugaredLogger|raw}}, client {{.clientsetInterface|raw}}, lister {{.resourceLister|raw}}, recorder {{.recordEventRecorder|raw}}, r Interface{{if .hasClass}}, classFilter func(interface{}) bool{{end}}, options ...{{.controllerOptions|raw}} ) {{.controllerReconciler|raw}} { // Check the options function input. It should be 0 or 1. if len(options) > 1 { logger.Fatalf("up to one options struct is supported, found %d", len(options)) @@ -220,7 +220,7 @@ func NewReconciler(ctx {{.contextContext|raw}}, logger *{{.zapSugaredLogger|raw} Lister: lister, Recorder: recorder, reconciler: r, - {{if .hasClass}}classValue: classValue,{{end}} + {{if .hasClass}}classFilter: classFilter,{{end}} } for _, opts := range options { @@ -263,10 +263,10 @@ func (r *reconcilerImpl) Reconcile(ctx {{.contextContext|raw}}, key string) erro return err } {{if .hasClass}} - if classValue, found := original.GetAnnotations()[ClassAnnotationKey]; !found || classValue != r.classValue { + if !r.classFilter(original) { logger.Debugw("Skip reconciling resource, class annotation value does not match reconciler instance value.", zap.String("classKey", ClassAnnotationKey), - zap.String("issue", classValue+"!="+r.classValue)) + zap.String("classValue", original.GetAnnotations()[ClassAnnotationKey])) return nil } {{end}}