From 101b405b3a69d197fe05bd2e76389c0376167ae2 Mon Sep 17 00:00:00 2001 From: Jose Armesto Date: Wed, 29 Sep 2021 17:48:01 +0200 Subject: [PATCH] :bug: Use the watch filter label when watching resources --- bootstrap/kubeadm/controllers/kubeadmconfig_controller.go | 3 +-- controllers/machine_controller.go | 5 ++++- controllers/machinedeployment_controller.go | 5 ++++- controllers/machinehealthcheck_controller.go | 5 ++++- controllers/machineset_controller.go | 5 ++++- exp/controllers/machinepool_controller.go | 5 ++++- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bootstrap/kubeadm/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/controllers/kubeadmconfig_controller.go index d0829c066813..b80ee52a7427 100644 --- a/bootstrap/kubeadm/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/controllers/kubeadmconfig_controller.go @@ -98,11 +98,10 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl b := ctrl.NewControllerManagedBy(mgr). For(&bootstrapv1.KubeadmConfig{}). WithOptions(options). - WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)). Watches( &source.Kind{Type: &clusterv1.Machine{}}, handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc), - ) + ).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)) if feature.Gates.Enabled(feature.MachinePool) { b = b.Watches( diff --git a/controllers/machine_controller.go b/controllers/machine_controller.go index fa7535b8f8c7..7d8a712e47de 100644 --- a/controllers/machine_controller.go +++ b/controllers/machine_controller.go @@ -103,7 +103,10 @@ func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(clusterToMachines), // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.All(ctrl.LoggerFrom(ctx), + predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), + ), ) if err != nil { return errors.Wrap(err, "failed to add Watch for Clusters to controller manager") diff --git a/controllers/machinedeployment_controller.go b/controllers/machinedeployment_controller.go index b6118c0dcb1f..ff5d65dab460 100644 --- a/controllers/machinedeployment_controller.go +++ b/controllers/machinedeployment_controller.go @@ -83,7 +83,10 @@ func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(clusterToMachineDeployments), // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.All(ctrl.LoggerFrom(ctx), + predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), + ), ) if err != nil { return errors.Wrap(err, "failed to add Watch for Clusters to controller manager") diff --git a/controllers/machinehealthcheck_controller.go b/controllers/machinehealthcheck_controller.go index 0df5e61d4687..108d5c23be45 100644 --- a/controllers/machinehealthcheck_controller.go +++ b/controllers/machinehealthcheck_controller.go @@ -97,7 +97,10 @@ func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(r.clusterToMachineHealthCheck), // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.All(ctrl.LoggerFrom(ctx), + predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), + ), ) if err != nil { return errors.Wrap(err, "failed to add Watch for Clusters to controller manager") diff --git a/controllers/machineset_controller.go b/controllers/machineset_controller.go index 4122ee96e152..aef7df609ad9 100644 --- a/controllers/machineset_controller.go +++ b/controllers/machineset_controller.go @@ -98,7 +98,10 @@ func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(clusterToMachineSets), // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.All(ctrl.LoggerFrom(ctx), + predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), + ), ) if err != nil { return errors.Wrap(err, "failed to add Watch for Clusters to controller manager") diff --git a/exp/controllers/machinepool_controller.go b/exp/controllers/machinepool_controller.go index d2061cd30b31..5693d22574f0 100644 --- a/exp/controllers/machinepool_controller.go +++ b/exp/controllers/machinepool_controller.go @@ -83,7 +83,10 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M &source.Kind{Type: &clusterv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(clusterToMachinePools), // TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources? - predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.All(ctrl.LoggerFrom(ctx), + predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)), + predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue), + ), ) if err != nil { return errors.Wrap(err, "failed adding Watch for Cluster to controller manager")