From 1dd31ad585380336553894ca029f15e56d650f99 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Tue, 21 Feb 2023 16:07:10 +0100 Subject: [PATCH 1/2] Generator: allow reconcilers to listen to leader promotion events Signed-off-by: Pierangelo Di Pilato --- .../cmd/injection-gen/generators/reconciler_controller.go | 8 ++++++++ controller/options.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/codegen/cmd/injection-gen/generators/reconciler_controller.go b/codegen/cmd/injection-gen/generators/reconciler_controller.go index 376623537a..417be9258e 100644 --- a/codegen/cmd/injection-gen/generators/reconciler_controller.go +++ b/codegen/cmd/injection-gen/generators/reconciler_controller.go @@ -230,10 +230,15 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu lister := {{.type|lowercaseSingular}}Informer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt {{.reconcilerBucket|raw}}) {} rec := &reconcilerImpl{ LeaderAwareFuncs: {{.reconcilerLeaderAwareFuncs|raw}}{ PromoteFunc: func(bkt {{.reconcilerBucket|raw}}, enq func({{.reconcilerBucket|raw}}, {{.typesNamespacedName|raw}})) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List({{.labelsEverything|raw}}()) if err != nil { return err @@ -295,6 +300,9 @@ func NewImpl(ctx {{.contextContext|raw}}, r Interface{{if .hasClass}}, classValu if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/controller/options.go b/controller/options.go index 4eef0eb5e7..574ef003f4 100644 --- a/controller/options.go +++ b/controller/options.go @@ -46,6 +46,10 @@ type Options struct { // Objects that pass the filter (return true) will be reconciled when a new leader is promoted. // If no filter is specified, all objects will be reconciled. PromoteFilterFunc func(obj interface{}) bool + + // PromoteFunc is called when a reconciler is promoted for the given bucket + // The provided function must not block execution. + PromoteFunc func(bkt reconciler.Bucket) } // OptionsFn is a callback method signature that accepts an Impl and returns From bb5e80922b4654c01034b8c23e59c72d821c2db0 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Tue, 21 Feb 2023 16:07:25 +0100 Subject: [PATCH 2/2] Run hack/update-codegen.sh Signed-off-by: Pierangelo Di Pilato --- .../v1/customresourcedefinition/controller.go | 8 ++++++++ .../v1beta1/customresourcedefinition/controller.go | 8 ++++++++ .../v1/mutatingwebhookconfiguration/controller.go | 8 ++++++++ .../v1/validatingwebhookconfiguration/controller.go | 8 ++++++++ .../v1beta1/mutatingwebhookconfiguration/controller.go | 8 ++++++++ .../v1beta1/validatingwebhookconfiguration/controller.go | 8 ++++++++ .../kube/reconciler/apps/v1/deployment/controller.go | 8 ++++++++ .../kube/reconciler/apps/v1beta1/deployment/controller.go | 8 ++++++++ .../kube/reconciler/apps/v1beta2/deployment/controller.go | 8 ++++++++ .../kube/reconciler/batch/v1/cronjob/controller.go | 8 ++++++++ .../kube/reconciler/batch/v1beta1/cronjob/controller.go | 8 ++++++++ .../kube/reconciler/core/v1/configmap/controller.go | 8 ++++++++ .../kube/reconciler/core/v1/namespace/controller.go | 8 ++++++++ .../injection/kube/reconciler/core/v1/node/controller.go | 8 ++++++++ .../injection/kube/reconciler/core/v1/pod/controller.go | 8 ++++++++ .../kube/reconciler/core/v1/secret/controller.go | 8 ++++++++ .../extensions/v1beta1/deployment/controller.go | 8 ++++++++ .../extensions/v1beta1/networkpolicy/controller.go | 8 ++++++++ .../reconciler/networking/v1/networkpolicy/controller.go | 8 ++++++++ 19 files changed, 152 insertions(+) diff --git a/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/controller.go b/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/controller.go index 75dc06c8d0..91026d6727 100644 --- a/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/controller.go +++ b/client/injection/apiextensions/reconciler/apiextensions/v1/customresourcedefinition/controller.go @@ -64,10 +64,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := customresourcedefinitionInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -125,6 +130,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/apiextensions/reconciler/apiextensions/v1beta1/customresourcedefinition/controller.go b/client/injection/apiextensions/reconciler/apiextensions/v1beta1/customresourcedefinition/controller.go index 49ee4b8956..a5cbe322dc 100644 --- a/client/injection/apiextensions/reconciler/apiextensions/v1beta1/customresourcedefinition/controller.go +++ b/client/injection/apiextensions/reconciler/apiextensions/v1beta1/customresourcedefinition/controller.go @@ -64,10 +64,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := customresourcedefinitionInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -125,6 +130,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/admissionregistration/v1/mutatingwebhookconfiguration/controller.go b/client/injection/kube/reconciler/admissionregistration/v1/mutatingwebhookconfiguration/controller.go index 5118aad855..a006f0b9b0 100644 --- a/client/injection/kube/reconciler/admissionregistration/v1/mutatingwebhookconfiguration/controller.go +++ b/client/injection/kube/reconciler/admissionregistration/v1/mutatingwebhookconfiguration/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := mutatingwebhookconfigurationInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/admissionregistration/v1/validatingwebhookconfiguration/controller.go b/client/injection/kube/reconciler/admissionregistration/v1/validatingwebhookconfiguration/controller.go index ad13541ffd..a71c59bc72 100644 --- a/client/injection/kube/reconciler/admissionregistration/v1/validatingwebhookconfiguration/controller.go +++ b/client/injection/kube/reconciler/admissionregistration/v1/validatingwebhookconfiguration/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := validatingwebhookconfigurationInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/admissionregistration/v1beta1/mutatingwebhookconfiguration/controller.go b/client/injection/kube/reconciler/admissionregistration/v1beta1/mutatingwebhookconfiguration/controller.go index a7643abe24..60a336dc9d 100644 --- a/client/injection/kube/reconciler/admissionregistration/v1beta1/mutatingwebhookconfiguration/controller.go +++ b/client/injection/kube/reconciler/admissionregistration/v1beta1/mutatingwebhookconfiguration/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := mutatingwebhookconfigurationInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/admissionregistration/v1beta1/validatingwebhookconfiguration/controller.go b/client/injection/kube/reconciler/admissionregistration/v1beta1/validatingwebhookconfiguration/controller.go index aa9191f2c7..1d09ccbb2e 100644 --- a/client/injection/kube/reconciler/admissionregistration/v1beta1/validatingwebhookconfiguration/controller.go +++ b/client/injection/kube/reconciler/admissionregistration/v1beta1/validatingwebhookconfiguration/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := validatingwebhookconfigurationInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/apps/v1/deployment/controller.go b/client/injection/kube/reconciler/apps/v1/deployment/controller.go index 10d85684e9..c6e60be43e 100644 --- a/client/injection/kube/reconciler/apps/v1/deployment/controller.go +++ b/client/injection/kube/reconciler/apps/v1/deployment/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := deploymentInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/apps/v1beta1/deployment/controller.go b/client/injection/kube/reconciler/apps/v1beta1/deployment/controller.go index bd1c019f0a..ed4c55916f 100644 --- a/client/injection/kube/reconciler/apps/v1beta1/deployment/controller.go +++ b/client/injection/kube/reconciler/apps/v1beta1/deployment/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := deploymentInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/apps/v1beta2/deployment/controller.go b/client/injection/kube/reconciler/apps/v1beta2/deployment/controller.go index 9825abe902..3895861b4d 100644 --- a/client/injection/kube/reconciler/apps/v1beta2/deployment/controller.go +++ b/client/injection/kube/reconciler/apps/v1beta2/deployment/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := deploymentInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/batch/v1/cronjob/controller.go b/client/injection/kube/reconciler/batch/v1/cronjob/controller.go index 5a1adec49b..fc7f54ab3b 100644 --- a/client/injection/kube/reconciler/batch/v1/cronjob/controller.go +++ b/client/injection/kube/reconciler/batch/v1/cronjob/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := cronjobInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/batch/v1beta1/cronjob/controller.go b/client/injection/kube/reconciler/batch/v1beta1/cronjob/controller.go index 06c2e34197..5e194b710f 100644 --- a/client/injection/kube/reconciler/batch/v1beta1/cronjob/controller.go +++ b/client/injection/kube/reconciler/batch/v1beta1/cronjob/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := cronjobInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/core/v1/configmap/controller.go b/client/injection/kube/reconciler/core/v1/configmap/controller.go index fb419d8c6e..522e30ec6e 100644 --- a/client/injection/kube/reconciler/core/v1/configmap/controller.go +++ b/client/injection/kube/reconciler/core/v1/configmap/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := configmapInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/core/v1/namespace/controller.go b/client/injection/kube/reconciler/core/v1/namespace/controller.go index 73b8657190..5eaf32f9ed 100644 --- a/client/injection/kube/reconciler/core/v1/namespace/controller.go +++ b/client/injection/kube/reconciler/core/v1/namespace/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := namespaceInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/core/v1/node/controller.go b/client/injection/kube/reconciler/core/v1/node/controller.go index 893b3682e6..6290245d91 100644 --- a/client/injection/kube/reconciler/core/v1/node/controller.go +++ b/client/injection/kube/reconciler/core/v1/node/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := nodeInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/core/v1/pod/controller.go b/client/injection/kube/reconciler/core/v1/pod/controller.go index 2f9456d101..68cc14c0c1 100644 --- a/client/injection/kube/reconciler/core/v1/pod/controller.go +++ b/client/injection/kube/reconciler/core/v1/pod/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := podInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/core/v1/secret/controller.go b/client/injection/kube/reconciler/core/v1/secret/controller.go index 6cb1a35cfe..0658bce592 100644 --- a/client/injection/kube/reconciler/core/v1/secret/controller.go +++ b/client/injection/kube/reconciler/core/v1/secret/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := secretInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -120,6 +125,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/extensions/v1beta1/deployment/controller.go b/client/injection/kube/reconciler/extensions/v1beta1/deployment/controller.go index c63f893619..6e7a912ebc 100644 --- a/client/injection/kube/reconciler/extensions/v1beta1/deployment/controller.go +++ b/client/injection/kube/reconciler/extensions/v1beta1/deployment/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := deploymentInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/extensions/v1beta1/networkpolicy/controller.go b/client/injection/kube/reconciler/extensions/v1beta1/networkpolicy/controller.go index a2cdd7aee7..c00e3c5372 100644 --- a/client/injection/kube/reconciler/extensions/v1beta1/networkpolicy/controller.go +++ b/client/injection/kube/reconciler/extensions/v1beta1/networkpolicy/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := networkpolicyInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName) diff --git a/client/injection/kube/reconciler/networking/v1/networkpolicy/controller.go b/client/injection/kube/reconciler/networking/v1/networkpolicy/controller.go index 6e026415a0..115ebd98ed 100644 --- a/client/injection/kube/reconciler/networking/v1/networkpolicy/controller.go +++ b/client/injection/kube/reconciler/networking/v1/networkpolicy/controller.go @@ -62,10 +62,15 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF lister := networkpolicyInformer.Lister() var promoteFilterFunc func(obj interface{}) bool + var promoteFunc = func(bkt reconciler.Bucket) {} rec := &reconcilerImpl{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + + // Signal promotion event + promoteFunc(bkt) + all, err := lister.List(labels.Everything()) if err != nil { return err @@ -123,6 +128,9 @@ func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsF if opts.PromoteFilterFunc != nil { promoteFilterFunc = opts.PromoteFilterFunc } + if opts.PromoteFunc != nil { + promoteFunc = opts.PromoteFunc + } } rec.Recorder = createRecorder(ctx, agentName)