Skip to content

Commit c46b8d9

Browse files
authored
Merge pull request #8789 from sbueringer/pr-watchfilter-capd
🐛 CAPD: Implement watch filter
2 parents dc5f916 + cbde5a2 commit c46b8d9

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

test/infrastructure/docker/controllers/alias.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type DockerMachineReconciler struct {
3737
Client client.Client
3838
ContainerRuntime container.Runtime
3939
Tracker *remote.ClusterCacheTracker
40+
41+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
42+
WatchFilterValue string
4043
}
4144

4245
// SetupWithManager sets up the reconciler with the Manager.
@@ -45,19 +48,24 @@ func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl
4548
Client: r.Client,
4649
ContainerRuntime: r.ContainerRuntime,
4750
Tracker: r.Tracker,
51+
WatchFilterValue: r.WatchFilterValue,
4852
}).SetupWithManager(ctx, mgr, options)
4953
}
5054

5155
// DockerClusterReconciler reconciles a DockerMachine object.
5256
type DockerClusterReconciler struct {
5357
Client client.Client
5458
ContainerRuntime container.Runtime
59+
60+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
61+
WatchFilterValue string
5562
}
5663

5764
// SetupWithManager sets up the reconciler with the Manager.
5865
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5966
return (&dockercontrollers.DockerClusterReconciler{
6067
Client: r.Client,
6168
ContainerRuntime: r.ContainerRuntime,
69+
WatchFilterValue: r.WatchFilterValue,
6270
}).SetupWithManager(ctx, mgr, options)
6371
}

test/infrastructure/docker/exp/controllers/alias.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type DockerMachinePoolReconciler struct {
3636
Scheme *runtime.Scheme
3737
ContainerRuntime container.Runtime
3838
Tracker *remote.ClusterCacheTracker
39+
40+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
41+
WatchFilterValue string
3942
}
4043

4144
// SetupWithManager will add watches for this controller.
@@ -45,5 +48,6 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr
4548
Scheme: r.Scheme,
4649
ContainerRuntime: r.ContainerRuntime,
4750
Tracker: r.Tracker,
51+
WatchFilterValue: r.WatchFilterValue,
4852
}).SetupWithManager(ctx, mgr, options)
4953
}

test/infrastructure/docker/exp/internal/controllers/dockermachinepool_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ type DockerMachinePoolReconciler struct {
5252
Scheme *runtime.Scheme
5353
ContainerRuntime container.Runtime
5454
Tracker *remote.ClusterCacheTracker
55+
56+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
57+
WatchFilterValue string
5558
}
5659

5760
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockermachinepools,verbs=get;list;watch;create;update;patch;delete
@@ -148,7 +151,7 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr
148151
err = ctrl.NewControllerManagedBy(mgr).
149152
For(&infraexpv1.DockerMachinePool{}).
150153
WithOptions(options).
151-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
154+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
152155
Watches(
153156
&expv1.MachinePool{},
154157
handler.EnqueueRequestsFromMapFunc(utilexp.MachinePoolToInfrastructureMapFunc(

test/infrastructure/docker/internal/controllers/dockercluster_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import (
4444
type DockerClusterReconciler struct {
4545
client.Client
4646
ContainerRuntime container.Runtime
47+
48+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
49+
WatchFilterValue string
4750
}
4851

4952
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockerclusters,verbs=get;list;watch;create;update;patch;delete
@@ -196,7 +199,7 @@ func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl
196199
err := ctrl.NewControllerManagedBy(mgr).
197200
For(&infrav1.DockerCluster{}).
198201
WithOptions(options).
199-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
202+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
200203
Watches(
201204
&clusterv1.Cluster{},
202205
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("DockerCluster"), mgr.GetClient(), &infrav1.DockerCluster{})),

test/infrastructure/docker/internal/controllers/dockermachine_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type DockerMachineReconciler struct {
5353
client.Client
5454
ContainerRuntime container.Runtime
5555
Tracker *remote.ClusterCacheTracker
56+
57+
// WatchFilterValue is the label value used to filter events prior to reconciliation.
58+
WatchFilterValue string
5659
}
5760

5861
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockermachines,verbs=get;list;watch;create;update;patch;delete
@@ -427,7 +430,7 @@ func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl
427430
err = ctrl.NewControllerManagedBy(mgr).
428431
For(&infrav1.DockerMachine{}).
429432
WithOptions(options).
430-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
433+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
431434
Watches(
432435
&clusterv1.Machine{},
433436
handler.EnqueueRequestsFromMapFunc(util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("DockerMachine"))),

test/infrastructure/docker/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
272272
}
273273

274274
if err := (&remote.ClusterCacheReconciler{
275-
Client: mgr.GetClient(),
276-
Tracker: tracker,
275+
Client: mgr.GetClient(),
276+
Tracker: tracker,
277+
WatchFilterValue: watchFilterValue,
277278
}).SetupWithManager(ctx, mgr, controller.Options{
278279
MaxConcurrentReconciles: concurrency,
279280
}); err != nil {
@@ -285,6 +286,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
285286
Client: mgr.GetClient(),
286287
ContainerRuntime: runtimeClient,
287288
Tracker: tracker,
289+
WatchFilterValue: watchFilterValue,
288290
}).SetupWithManager(ctx, mgr, controller.Options{
289291
MaxConcurrentReconciles: concurrency,
290292
}); err != nil {
@@ -295,6 +297,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
295297
if err := (&controllers.DockerClusterReconciler{
296298
Client: mgr.GetClient(),
297299
ContainerRuntime: runtimeClient,
300+
WatchFilterValue: watchFilterValue,
298301
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
299302
setupLog.Error(err, "unable to create controller", "controller", "DockerCluster")
300303
os.Exit(1)
@@ -305,6 +308,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
305308
Client: mgr.GetClient(),
306309
ContainerRuntime: runtimeClient,
307310
Tracker: tracker,
311+
WatchFilterValue: watchFilterValue,
308312
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: concurrency}); err != nil {
309313
setupLog.Error(err, "unable to create controller", "controller", "DockerMachinePool")
310314
os.Exit(1)

0 commit comments

Comments
 (0)