Skip to content

Commit 75e533d

Browse files
committed
Follow up on review comments
1 parent 33afd2d commit 75e533d

12 files changed

+57
-69
lines changed

api/v1alpha4/common_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const (
5757
//
5858
// Controllers which allow for selective reconciliation may check this label and proceed
5959
// with reconciliation of the object only if this label and a configured value is present.
60-
WatchLabel = "cluster.x-k8s.io/watch"
60+
WatchLabel = "cluster.x-k8s.io/watch-filter"
6161

6262
// DeleteMachineAnnotation marks control plane and worker nodes that will be given priority for deletion
6363
// when KCP or a machineset scales down. This annotation is given top priority on all delete policies.

controllers/cluster_controller.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const (
6363

6464
// ClusterReconciler reconciles a Cluster object
6565
type ClusterReconciler struct {
66-
Client client.Client
67-
Config
66+
Client client.Client
67+
WatchFilterValue string
6868

6969
restConfig *rest.Config
7070
recorder record.EventRecorder
@@ -79,7 +79,7 @@ func (r *ClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
7979
handler.EnqueueRequestsFromMapFunc(r.controlPlaneMachineToCluster),
8080
).
8181
WithOptions(options).
82-
WithEventFilter(predicates.ResourceNotPausedAndHasLabel(ctrl.LoggerFrom(ctx), r.Config.WatchLabelValue)).
82+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
8383
Build(r)
8484

8585
if err != nil {

controllers/machine_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ var (
6969

7070
// MachineReconciler reconciles a Machine object
7171
type MachineReconciler struct {
72-
Client client.Client
73-
Config
74-
Tracker *remote.ClusterCacheTracker
72+
Client client.Client
73+
Tracker *remote.ClusterCacheTracker
74+
WatchFilterValue string
7575

7676
controller controller.Controller
7777
restConfig *rest.Config
@@ -88,7 +88,7 @@ func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
8888
controller, err := ctrl.NewControllerManagedBy(mgr).
8989
For(&clusterv1.Machine{}).
9090
WithOptions(options).
91-
WithEventFilter(predicates.ResourceNotPausedAndHasLabel(ctrl.LoggerFrom(ctx), r.Config.WatchLabelValue)).
91+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
9292
Build(r)
9393
if err != nil {
9494
return errors.Wrap(err, "failed setting up with a controller manager")

controllers/machinedeployment_controller.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ var (
5353

5454
// MachineDeploymentReconciler reconciles a MachineDeployment object
5555
type MachineDeploymentReconciler struct {
56-
Client client.Client
57-
Config
56+
Client client.Client
57+
WatchFilterValue string
5858

5959
recorder record.EventRecorder
6060
restConfig *rest.Config
@@ -74,7 +74,7 @@ func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr
7474
handler.EnqueueRequestsFromMapFunc(r.MachineSetToDeployments),
7575
).
7676
WithOptions(options).
77-
WithEventFilter(predicates.ResourceNotPausedAndHasLabel(ctrl.LoggerFrom(ctx), r.Config.WatchLabelValue)).
77+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
7878
Build(r)
7979
if err != nil {
8080
return errors.Wrap(err, "failed setting up with a controller manager")

controllers/machinehealthcheck_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ const (
6565

6666
// MachineHealthCheckReconciler reconciles a MachineHealthCheck object
6767
type MachineHealthCheckReconciler struct {
68-
Client client.Client
69-
Config
70-
Tracker *remote.ClusterCacheTracker
68+
Client client.Client
69+
Tracker *remote.ClusterCacheTracker
70+
WatchFilterValue string
7171

7272
controller controller.Controller
7373
recorder record.EventRecorder
@@ -81,7 +81,7 @@ func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr
8181
handler.EnqueueRequestsFromMapFunc(r.machineToMachineHealthCheck),
8282
).
8383
WithOptions(options).
84-
WithEventFilter(predicates.ResourceNotPausedAndHasLabel(ctrl.LoggerFrom(ctx), r.Config.WatchLabelValue)).
84+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
8585
Build(r)
8686
if err != nil {
8787
return errors.Wrap(err, "failed setting up with a controller manager")

controllers/machineset_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ var (
6767

6868
// MachineSetReconciler reconciles a MachineSet object
6969
type MachineSetReconciler struct {
70-
Client client.Client
71-
Config
72-
Tracker *remote.ClusterCacheTracker
70+
Client client.Client
71+
Tracker *remote.ClusterCacheTracker
72+
WatchFilterValue string
7373

7474
recorder record.EventRecorder
7575
restConfig *rest.Config
@@ -89,7 +89,7 @@ func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
8989
handler.EnqueueRequestsFromMapFunc(r.MachineToMachineSets),
9090
).
9191
WithOptions(options).
92-
WithEventFilter(predicates.ResourceNotPausedAndHasLabel(ctrl.LoggerFrom(ctx), r.Config.WatchLabelValue)).
92+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
9393
Build(r)
9494
if err != nil {
9595
return errors.Wrap(err, "failed setting up with a controller manager")

controllers/types.go

-23
This file was deleted.

exp/addons/controllers/clusterresourceset_controller.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ var (
6161

6262
// ClusterResourceSetReconciler reconciles a ClusterResourceSet object
6363
type ClusterResourceSetReconciler struct {
64-
Client client.Client
65-
Tracker *remote.ClusterCacheTracker
64+
Client client.Client
65+
Tracker *remote.ClusterCacheTracker
66+
WatchFilterValue string
6667
}
6768

6869
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
@@ -89,7 +90,7 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
8990
),
9091
).
9192
WithOptions(options).
92-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
93+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
9394
Complete(r)
9495

9596
if err != nil {

exp/addons/controllers/clusterresourcesetbinding_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import (
3737

3838
// ClusterResourceSetBindingReconciler reconciles a ClusterResourceSetBinding object
3939
type ClusterResourceSetBindingReconciler struct {
40-
Client client.Client
40+
Client client.Client
41+
WatchFilterValue string
4142
}
4243

4344
func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
@@ -48,7 +49,7 @@ func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Conte
4849
handler.EnqueueRequestsFromMapFunc(r.clusterToClusterResourceSetBinding),
4950
).
5051
WithOptions(options).
51-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
52+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
5253
Build(r)
5354
if err != nil {
5455
return errors.Wrap(err, "failed setting up with a controller manager")

exp/controllers/machinepool_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ import (
5353

5454
// MachinePoolReconciler reconciles a MachinePool object
5555
type MachinePoolReconciler struct {
56-
Client client.Client
56+
Client client.Client
57+
WatchFilterValue string
5758

5859
config *rest.Config
5960
controller controller.Controller
@@ -70,7 +71,7 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
7071
c, err := ctrl.NewControllerManagedBy(mgr).
7172
For(&expv1.MachinePool{}).
7273
WithOptions(options).
73-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
74+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
7475
Build(r)
7576
if err != nil {
7677
return errors.Wrap(err, "failed setting up with a controller manager")

main.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var (
5959
leaderElectionRenewDeadline time.Duration
6060
leaderElectionRetryPeriod time.Duration
6161
watchNamespace string
62-
watchLabelValue string
62+
watchFilterValue string
6363
profilerAddress string
6464
clusterConcurrency int
6565
machineConcurrency int
@@ -104,7 +104,7 @@ func InitFlags(fs *pflag.FlagSet) {
104104
fs.StringVar(&watchNamespace, "namespace", "",
105105
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
106106

107-
fs.StringVar(&watchLabelValue, "watch-label", "",
107+
fs.StringVar(&watchFilterValue, "watch-filter", "",
108108
fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
109109

110110
fs.StringVar(&profilerAddress, "profiler-address", "",
@@ -233,35 +233,40 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
233233
}
234234

235235
if err := (&controllers.ClusterReconciler{
236-
Client: mgr.GetClient(),
236+
Client: mgr.GetClient(),
237+
WatchFilterValue: watchFilterValue,
237238
}).SetupWithManager(ctx, mgr, concurrency(clusterConcurrency)); err != nil {
238239
setupLog.Error(err, "unable to create controller", "controller", "Cluster")
239240
os.Exit(1)
240241
}
241242
if err := (&controllers.MachineReconciler{
242-
Client: mgr.GetClient(),
243-
Tracker: tracker,
243+
Client: mgr.GetClient(),
244+
Tracker: tracker,
245+
WatchFilterValue: watchFilterValue,
244246
}).SetupWithManager(ctx, mgr, concurrency(machineConcurrency)); err != nil {
245247
setupLog.Error(err, "unable to create controller", "controller", "Machine")
246248
os.Exit(1)
247249
}
248250
if err := (&controllers.MachineSetReconciler{
249-
Client: mgr.GetClient(),
250-
Tracker: tracker,
251+
Client: mgr.GetClient(),
252+
Tracker: tracker,
253+
WatchFilterValue: watchFilterValue,
251254
}).SetupWithManager(ctx, mgr, concurrency(machineSetConcurrency)); err != nil {
252255
setupLog.Error(err, "unable to create controller", "controller", "MachineSet")
253256
os.Exit(1)
254257
}
255258
if err := (&controllers.MachineDeploymentReconciler{
256-
Client: mgr.GetClient(),
259+
Client: mgr.GetClient(),
260+
WatchFilterValue: watchFilterValue,
257261
}).SetupWithManager(ctx, mgr, concurrency(machineDeploymentConcurrency)); err != nil {
258262
setupLog.Error(err, "unable to create controller", "controller", "MachineDeployment")
259263
os.Exit(1)
260264
}
261265

262266
if feature.Gates.Enabled(feature.MachinePool) {
263267
if err := (&expcontrollers.MachinePoolReconciler{
264-
Client: mgr.GetClient(),
268+
Client: mgr.GetClient(),
269+
WatchFilterValue: watchFilterValue,
265270
}).SetupWithManager(ctx, mgr, concurrency(machinePoolConcurrency)); err != nil {
266271
setupLog.Error(err, "unable to create controller", "controller", "MachinePool")
267272
os.Exit(1)
@@ -270,23 +275,26 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
270275

271276
if feature.Gates.Enabled(feature.ClusterResourceSet) {
272277
if err := (&addonscontrollers.ClusterResourceSetReconciler{
273-
Client: mgr.GetClient(),
274-
Tracker: tracker,
278+
Client: mgr.GetClient(),
279+
Tracker: tracker,
280+
WatchFilterValue: watchFilterValue,
275281
}).SetupWithManager(ctx, mgr, concurrency(clusterResourceSetConcurrency)); err != nil {
276282
setupLog.Error(err, "unable to create controller", "controller", "ClusterResourceSet")
277283
os.Exit(1)
278284
}
279285
if err := (&addonscontrollers.ClusterResourceSetBindingReconciler{
280-
Client: mgr.GetClient(),
286+
Client: mgr.GetClient(),
287+
WatchFilterValue: watchFilterValue,
281288
}).SetupWithManager(ctx, mgr, concurrency(clusterResourceSetConcurrency)); err != nil {
282289
setupLog.Error(err, "unable to create controller", "controller", "ClusterResourceSetBinding")
283290
os.Exit(1)
284291
}
285292
}
286293

287294
if err := (&controllers.MachineHealthCheckReconciler{
288-
Client: mgr.GetClient(),
289-
Tracker: tracker,
295+
Client: mgr.GetClient(),
296+
Tracker: tracker,
297+
WatchFilterValue: watchFilterValue,
290298
}).SetupWithManager(ctx, mgr, concurrency(machineHealthCheckConcurrency)); err != nil {
291299
setupLog.Error(err, "unable to create controller", "controller", "MachineHealthCheck")
292300
os.Exit(1)

util/predicates/generic_predicates.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ func Any(logger logr.Logger, predicates ...predicate.Funcs) predicate.Funcs {
128128
}
129129
}
130130

131-
// ResourceHasLabel returns a predicate that returns true only if the provided resource contains
131+
// ResourceHasFilterLabel returns a predicate that returns true only if the provided resource contains
132132
// a label with the WatchLabel key and the configured label value exactly.
133-
func ResourceHasLabel(logger logr.Logger, labelValue string) predicate.Funcs {
133+
func ResourceHasFilterLabel(logger logr.Logger, labelValue string) predicate.Funcs {
134134
return predicate.Funcs{
135135
UpdateFunc: func(e event.UpdateEvent) bool {
136136
return processIfLabelMatch(logger.WithValues("predicate", "updateEvent"), e.ObjectNew, labelValue)
@@ -177,10 +177,10 @@ func ResourceNotPaused(logger logr.Logger) predicate.Funcs {
177177
}
178178
}
179179

180-
// ResourceNotPausedAndHasLabel returns a predicate that returns true only if the
181-
// ResourceNotPaused and ResourceHasLabel predicates return true.
182-
func ResourceNotPausedAndHasLabel(logger logr.Logger, labelValue string) predicate.Funcs {
183-
return All(logger, ResourceNotPaused(logger), ResourceHasLabel(logger, labelValue))
180+
// ResourceNotPausedAndHasFilterLabel returns a predicate that returns true only if the
181+
// ResourceNotPaused and ResourceHasFilterLabel predicates return true.
182+
func ResourceNotPausedAndHasFilterLabel(logger logr.Logger, labelValue string) predicate.Funcs {
183+
return All(logger, ResourceNotPaused(logger), ResourceHasFilterLabel(logger, labelValue))
184184
}
185185

186186
func processIfNotPaused(logger logr.Logger, obj client.Object) bool {

0 commit comments

Comments
 (0)