diff --git a/controllers/azurecluster_controller.go b/controllers/azurecluster_controller.go index 387c9f3cd5c..7614ff2890f 100644 --- a/controllers/azurecluster_controller.go +++ b/controllers/azurecluster_controller.go @@ -93,6 +93,7 @@ func (r *AzureClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl. &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("AzureCluster"))), predicates.ClusterUnpaused(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/controllers/azureidentity_controller.go b/controllers/azureidentity_controller.go index 202020e7ba6..32ccdafb1c3 100644 --- a/controllers/azureidentity_controller.go +++ b/controllers/azureidentity_controller.go @@ -84,6 +84,7 @@ func (r *AzureIdentityReconciler) SetupWithManager(ctx context.Context, mgr ctrl &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("AzureCluster"))), predicates.ClusterUnpaused(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/controllers/azurejson_machine_controller.go b/controllers/azurejson_machine_controller.go index 1de87768838..a42b60fcd6e 100644 --- a/controllers/azurejson_machine_controller.go +++ b/controllers/azurejson_machine_controller.go @@ -33,6 +33,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" + "sigs.k8s.io/cluster-api/util/predicates" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -52,6 +53,7 @@ type AzureJSONMachineReconciler struct { Log logr.Logger Recorder record.EventRecorder ReconcileTimeout time.Duration + WatchFilterValue string } // SetupWithManager initializes this controller with a manager. @@ -59,6 +61,7 @@ func (r *AzureJSONMachineReconciler) SetupWithManager(ctx context.Context, mgr c return ctrl.NewControllerManagedBy(mgr). For(&infrav1.AzureMachine{}). WithEventFilter(filterUnclonedMachinesPredicate{log: r.Log}). + WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Owns(&corev1.Secret{}). Complete(r) } diff --git a/controllers/azurejson_machinepool_controller.go b/controllers/azurejson_machinepool_controller.go index c5d1f22fd5e..4228fb28fae 100644 --- a/controllers/azurejson_machinepool_controller.go +++ b/controllers/azurejson_machinepool_controller.go @@ -31,6 +31,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/predicates" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -49,12 +50,14 @@ type AzureJSONMachinePoolReconciler struct { Log logr.Logger Recorder record.EventRecorder ReconcileTimeout time.Duration + WatchFilterValue string } // SetupWithManager initializes this controller with a manager. func (r *AzureJSONMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { return ctrl.NewControllerManagedBy(mgr). For(&expv1.AzureMachinePool{}). + WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Owns(&corev1.Secret{}). Complete(r) } diff --git a/controllers/azurejson_machinetemplate_controller.go b/controllers/azurejson_machinetemplate_controller.go index 77e74da983a..fbdcb579583 100644 --- a/controllers/azurejson_machinetemplate_controller.go +++ b/controllers/azurejson_machinetemplate_controller.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/tools/record" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" + "sigs.k8s.io/cluster-api/util/predicates" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -49,6 +50,7 @@ type AzureJSONTemplateReconciler struct { Log logr.Logger Recorder record.EventRecorder ReconcileTimeout time.Duration + WatchFilterValue string } // SetupWithManager initializes this controller with a manager. @@ -56,6 +58,7 @@ func (r *AzureJSONTemplateReconciler) SetupWithManager(ctx context.Context, mgr return ctrl.NewControllerManagedBy(mgr). WithOptions(options). For(&infrav1.AzureMachineTemplate{}). + WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Owns(&corev1.Secret{}). Complete(r) } diff --git a/controllers/azuremachine_controller.go b/controllers/azuremachine_controller.go index 0edd453182f..7afe5800a6d 100644 --- a/controllers/azuremachine_controller.go +++ b/controllers/azuremachine_controller.go @@ -113,6 +113,7 @@ func (r *AzureMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl. &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(azureMachineMapper), predicates.ClusterUnpausedAndInfrastructureReady(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/exp/controllers/azuremachinepool_controller.go b/exp/controllers/azuremachinepool_controller.go index 66c0f40e099..cd272e27181 100644 --- a/exp/controllers/azuremachinepool_controller.go +++ b/exp/controllers/azuremachinepool_controller.go @@ -126,6 +126,7 @@ func (ampr *AzureMachinePoolReconciler) SetupWithManager(ctx context.Context, mg &source.Kind{Type: &infrav1exp.AzureMachinePoolMachine{}}, handler.EnqueueRequestsFromMapFunc(AzureMachinePoolMachineMapper(mgr.GetScheme(), log)), MachinePoolMachineHasStateOrVersionChange(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ampr.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for AzureMachinePoolMachine") } @@ -140,6 +141,7 @@ func (ampr *AzureMachinePoolReconciler) SetupWithManager(ctx context.Context, mg &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(azureMachinePoolMapper), predicates.ClusterUnpausedAndInfrastructureReady(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ampr.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/exp/controllers/azuremachinepoolmachine_controller.go b/exp/controllers/azuremachinepoolmachine_controller.go index 4cdac3c59f6..a1b58d082a1 100644 --- a/exp/controllers/azuremachinepoolmachine_controller.go +++ b/exp/controllers/azuremachinepoolmachine_controller.go @@ -98,7 +98,7 @@ func (ampmr *AzureMachinePoolMachineController) SetupWithManager(ctx context.Con c, err := ctrl.NewControllerManagedBy(mgr). WithOptions(options.Options). For(&infrav1exp.AzureMachinePoolMachine{}). - WithEventFilter(predicates.ResourceNotPaused(log)). // don't queue reconcile if resource is paused + WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ampmr.WatchFilterValue)). Build(r) if err != nil { return errors.Wrapf(err, "error creating controller") @@ -109,6 +109,7 @@ func (ampmr *AzureMachinePoolMachineController) SetupWithManager(ctx context.Con &source.Kind{Type: &infrav1exp.AzureMachinePool{}}, handler.EnqueueRequestsFromMapFunc(AzureMachinePoolToAzureMachinePoolMachines(ctx, mgr.GetClient(), log)), MachinePoolModelHasChanged(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ampmr.WatchFilterValue), ); err != nil { return errors.Wrapf(err, "failed adding a watch for AzureMachinePool model changes") } diff --git a/exp/controllers/azuremanagedcluster_controller.go b/exp/controllers/azuremanagedcluster_controller.go index c6cbc8c88b3..4387f4bb948 100644 --- a/exp/controllers/azuremanagedcluster_controller.go +++ b/exp/controllers/azuremanagedcluster_controller.go @@ -83,6 +83,7 @@ func (r *AzureManagedClusterReconciler) SetupWithManager(ctx context.Context, mg &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1exp.GroupVersion.WithKind("AzureManagedCluster"))), predicates.ClusterUnpaused(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/exp/controllers/azuremanagedcontrolplane_controller.go b/exp/controllers/azuremanagedcontrolplane_controller.go index 09a226a8d75..14c4fccd8db 100644 --- a/exp/controllers/azuremanagedcontrolplane_controller.go +++ b/exp/controllers/azuremanagedcontrolplane_controller.go @@ -95,6 +95,7 @@ func (r *AzureManagedControlPlaneReconciler) SetupWithManager(ctx context.Contex &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1exp.GroupVersion.WithKind("AzureManagedControlPlane"))), predicates.ClusterUnpausedAndInfrastructureReady(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/exp/controllers/azuremanagedmachinepool_controller.go b/exp/controllers/azuremanagedmachinepool_controller.go index 131af62ad14..ac6f8a26370 100644 --- a/exp/controllers/azuremanagedmachinepool_controller.go +++ b/exp/controllers/azuremanagedmachinepool_controller.go @@ -108,6 +108,7 @@ func (r *AzureManagedMachinePoolReconciler) SetupWithManager(ctx context.Context &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1exp.GroupVersion.WithKind("AzureManagedMachinePool"))), predicates.ClusterUnpausedAndInfrastructureReady(log), + predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), ); err != nil { return errors.Wrap(err, "failed adding a watch for ready clusters") } diff --git a/main.go b/main.go index 9657454c11f..d49f248620e 100644 --- a/main.go +++ b/main.go @@ -342,6 +342,7 @@ func registerControllers(ctx context.Context, mgr manager.Manager) { Log: ctrl.Log.WithName("controllers").WithName("AzureJSONTemplate"), Recorder: mgr.GetEventRecorderFor("azurejsontemplate-reconciler"), ReconcileTimeout: reconcileTimeout, + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: azureMachineConcurrency}); err != nil { setupLog.Error(err, "unable to create controller", "controller", "AzureJSONTemplate") os.Exit(1) @@ -352,6 +353,7 @@ func registerControllers(ctx context.Context, mgr manager.Manager) { Log: ctrl.Log.WithName("controllers").WithName("AzureJSONMachine"), Recorder: mgr.GetEventRecorderFor("azurejsonmachine-reconciler"), ReconcileTimeout: reconcileTimeout, + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: azureMachineConcurrency}); err != nil { setupLog.Error(err, "unable to create controller", "controller", "AzureJSONMachine") os.Exit(1) @@ -408,6 +410,7 @@ func registerControllers(ctx context.Context, mgr manager.Manager) { Log: ctrl.Log.WithName("controllers").WithName("AzureJSONMachinePool"), Recorder: mgr.GetEventRecorderFor("azurejsonmachinepool-reconciler"), ReconcileTimeout: reconcileTimeout, + WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: azureMachinePoolConcurrency}); err != nil { setupLog.Error(err, "unable to create controller", "controller", "AzureJSONMachinePool") os.Exit(1)