Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 CAPD: Implement watch filter #8789

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/infrastructure/docker/controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type DockerMachineReconciler struct {
Client client.Client
ContainerRuntime container.Runtime
Tracker *remote.ClusterCacheTracker

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// SetupWithManager sets up the reconciler with the Manager.
Expand All @@ -45,19 +48,24 @@ func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl
Client: r.Client,
ContainerRuntime: r.ContainerRuntime,
Tracker: r.Tracker,
WatchFilterValue: r.WatchFilterValue,
}).SetupWithManager(ctx, mgr, options)
}

// DockerClusterReconciler reconciles a DockerMachine object.
type DockerClusterReconciler struct {
Client client.Client
ContainerRuntime container.Runtime

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// SetupWithManager sets up the reconciler with the Manager.
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
return (&dockercontrollers.DockerClusterReconciler{
Client: r.Client,
ContainerRuntime: r.ContainerRuntime,
WatchFilterValue: r.WatchFilterValue,
}).SetupWithManager(ctx, mgr, options)
}
4 changes: 4 additions & 0 deletions test/infrastructure/docker/exp/controllers/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type DockerMachinePoolReconciler struct {
Scheme *runtime.Scheme
ContainerRuntime container.Runtime
Tracker *remote.ClusterCacheTracker

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// SetupWithManager will add watches for this controller.
Expand All @@ -45,5 +48,6 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr
Scheme: r.Scheme,
ContainerRuntime: r.ContainerRuntime,
Tracker: r.Tracker,
WatchFilterValue: r.WatchFilterValue,
}).SetupWithManager(ctx, mgr, options)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type DockerMachinePoolReconciler struct {
Scheme *runtime.Scheme
ContainerRuntime container.Runtime
Tracker *remote.ClusterCacheTracker

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockermachinepools,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -148,7 +151,7 @@ func (r *DockerMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr
err = ctrl.NewControllerManagedBy(mgr).
For(&infraexpv1.DockerMachinePool{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Watches(
&expv1.MachinePool{},
handler.EnqueueRequestsFromMapFunc(utilexp.MachinePoolToInfrastructureMapFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import (
type DockerClusterReconciler struct {
client.Client
ContainerRuntime container.Runtime

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockerclusters,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -196,7 +199,7 @@ func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl
err := ctrl.NewControllerManagedBy(mgr).
For(&infrav1.DockerCluster{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Watches(
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("DockerCluster"), mgr.GetClient(), &infrav1.DockerCluster{})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type DockerMachineReconciler struct {
client.Client
ContainerRuntime container.Runtime
Tracker *remote.ClusterCacheTracker

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockermachines,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -427,7 +430,7 @@ func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl
err = ctrl.NewControllerManagedBy(mgr).
For(&infrav1.DockerMachine{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Watches(
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("DockerMachine"))),
Expand Down
8 changes: 6 additions & 2 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
}

if err := (&remote.ClusterCacheReconciler{
Client: mgr.GetClient(),
Tracker: tracker,
Client: mgr.GetClient(),
Tracker: tracker,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrency,
}); err != nil {
Expand All @@ -285,6 +286,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
Client: mgr.GetClient(),
ContainerRuntime: runtimeClient,
Tracker: tracker,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrency,
}); err != nil {
Expand All @@ -295,6 +297,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.DockerClusterReconciler{
Client: mgr.GetClient(),
ContainerRuntime: runtimeClient,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DockerCluster")
os.Exit(1)
Expand All @@ -305,6 +308,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
Client: mgr.GetClient(),
ContainerRuntime: runtimeClient,
Tracker: tracker,
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: concurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DockerMachinePool")
os.Exit(1)
Expand Down