Skip to content

Commit cc9a9da

Browse files
Tuomas Mäkinenfiunchinho
Tuomas Mäkinen
authored andcommitted
Add watch-filter support to kubeadm controlplane controller
1 parent b17a1bb commit cc9a9da

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

bootstrap/kubeadm/controllers/kubeadmconfig_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
121121
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmConfigs),
122122
predicates.All(ctrl.LoggerFrom(ctx),
123123
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
124-
predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
124+
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
125125
),
126126
)
127127
if err != nil {

controlplane/kubeadm/controllers/controller.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ import (
5959

6060
// KubeadmControlPlaneReconciler reconciles a KubeadmControlPlane object.
6161
type KubeadmControlPlaneReconciler struct {
62-
Client client.Client
63-
controller controller.Controller
64-
recorder record.EventRecorder
65-
Tracker *remote.ClusterCacheTracker
62+
Client client.Client
63+
controller controller.Controller
64+
recorder record.EventRecorder
65+
Tracker *remote.ClusterCacheTracker
66+
WatchFilterValue string
6667

6768
managementCluster internal.ManagementCluster
6869
managementClusterUncached internal.ManagementCluster
@@ -73,7 +74,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
7374
For(&controlplanev1.KubeadmControlPlane{}).
7475
Owns(&clusterv1.Machine{}).
7576
WithOptions(options).
76-
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
77+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
7778
Build(r)
7879
if err != nil {
7980
return errors.Wrap(err, "failed setting up with a controller manager")
@@ -82,7 +83,10 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
8283
err = c.Watch(
8384
&source.Kind{Type: &clusterv1.Cluster{}},
8485
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmControlPlane),
85-
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
86+
predicates.All(ctrl.LoggerFrom(ctx),
87+
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
88+
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
89+
),
8690
)
8791
if err != nil {
8892
return errors.Wrap(err, "failed adding Watch for Clusters to controller manager")

controlplane/kubeadm/main.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"context"
2121
"flag"
22+
"fmt"
2223
"math/rand"
2324
"net/http"
2425
_ "net/http/pprof"
@@ -68,6 +69,7 @@ var (
6869
leaderElectionLeaseDuration time.Duration
6970
leaderElectionRenewDeadline time.Duration
7071
leaderElectionRetryPeriod time.Duration
72+
watchFilterValue string
7173
watchNamespace string
7274
profilerAddress string
7375
kubeadmControlPlaneConcurrency int
@@ -106,6 +108,9 @@ func InitFlags(fs *pflag.FlagSet) {
106108
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
107109
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
108110

111+
fs.StringVar(&watchFilterValue, "watch-filter", "",
112+
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))
113+
109114
fs.IntVar(&webhookPort, "webhook-port", 9443,
110115
"Webhook Server port")
111116

@@ -193,17 +198,19 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
193198
os.Exit(1)
194199
}
195200
if err := (&remote.ClusterCacheReconciler{
196-
Client: mgr.GetClient(),
197-
Log: ctrl.Log.WithName("remote").WithName("ClusterCacheReconciler"),
198-
Tracker: tracker,
201+
Client: mgr.GetClient(),
202+
Log: ctrl.Log.WithName("remote").WithName("ClusterCacheReconciler"),
203+
Tracker: tracker,
204+
WatchFilterValue: watchFilterValue,
199205
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
200206
setupLog.Error(err, "unable to create controller", "controller", "ClusterCacheReconciler")
201207
os.Exit(1)
202208
}
203209

204210
if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
205-
Client: mgr.GetClient(),
206-
Tracker: tracker,
211+
Client: mgr.GetClient(),
212+
Tracker: tracker,
213+
WatchFilterValue: watchFilterValue,
207214
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
208215
setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane")
209216
os.Exit(1)

0 commit comments

Comments
 (0)