Skip to content

Commit 45af36e

Browse files
Pass label predicate everywhere
1 parent 220e0a5 commit 45af36e

File tree

22 files changed

+131
-144
lines changed

22 files changed

+131
-144
lines changed

bootstrap/kubeadm/controllers/alias.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
kubeadmbootstrapcontrollers "sigs.k8s.io/cluster-api/bootstrap/kubeadm/internal/controllers"
2828
"sigs.k8s.io/cluster-api/controllers/remote"
29+
"sigs.k8s.io/cluster-api/util/predicates"
2930
)
3031

3132
// Following types provides access to reconcilers implemented in internal/controllers, thus
@@ -43,8 +44,8 @@ type KubeadmConfigReconciler struct {
4344

4445
Tracker *remote.ClusterCacheTracker
4546

46-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
47-
WatchFilterValue string
47+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
48+
WatchFilterPredicate predicates.LabelMatcher
4849

4950
// TokenTTL is the amount of time a bootstrap token (and therefore a KubeadmConfig) will be valid.
5051
TokenTTL time.Duration
@@ -53,10 +54,10 @@ type KubeadmConfigReconciler struct {
5354
// SetupWithManager sets up the reconciler with the Manager.
5455
func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5556
return (&kubeadmbootstrapcontrollers.KubeadmConfigReconciler{
56-
Client: r.Client,
57-
SecretCachingClient: r.SecretCachingClient,
58-
Tracker: r.Tracker,
59-
WatchFilterValue: r.WatchFilterValue,
60-
TokenTTL: r.TokenTTL,
57+
Client: r.Client,
58+
SecretCachingClient: r.SecretCachingClient,
59+
Tracker: r.Tracker,
60+
WatchFilterPredicate: r.WatchFilterPredicate,
61+
TokenTTL: r.TokenTTL,
6162
}).SetupWithManager(ctx, mgr, options)
6263
}

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ type KubeadmConfigReconciler struct {
8181
Tracker *remote.ClusterCacheTracker
8282
KubeadmInitLock InitLocker
8383

84-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
85-
WatchFilterValue string
84+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
85+
WatchFilterPredicate predicates.LabelMatcher
8686

8787
// TokenTTL is the amount of time a bootstrap token (and therefore a KubeadmConfig) will be valid.
8888
TokenTTL time.Duration
@@ -111,7 +111,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
111111
Watches(
112112
&clusterv1.Machine{},
113113
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
114-
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue))
114+
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterPredicate))
115115

116116
if feature.Gates.Enabled(feature.MachinePool) {
117117
b = b.Watches(
@@ -126,7 +126,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
126126
builder.WithPredicates(
127127
predicates.All(ctrl.LoggerFrom(ctx),
128128
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
129-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
129+
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterPredicate),
130130
),
131131
),
132132
)

controllers/alias.go

+34-33
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
machinedeploymenttopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machinedeployment"
3636
machinesettopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machineset"
3737
runtimeclient "sigs.k8s.io/cluster-api/internal/runtime/client"
38+
"sigs.k8s.io/cluster-api/util/predicates"
3839
)
3940

4041
// Following types provides access to reconcilers implemented in internal/controllers, thus
@@ -46,16 +47,16 @@ type ClusterReconciler struct {
4647
UnstructuredCachingClient client.Client
4748
APIReader client.Reader
4849

49-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
50-
WatchFilterValue string
50+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
51+
WatchFilterPredicate predicates.LabelMatcher
5152
}
5253

5354
func (r *ClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5455
return (&clustercontroller.Reconciler{
5556
Client: r.Client,
5657
UnstructuredCachingClient: r.UnstructuredCachingClient,
5758
APIReader: r.APIReader,
58-
WatchFilterValue: r.WatchFilterValue,
59+
WatchFilterPredicate: r.WatchFilterPredicate,
5960
}).SetupWithManager(ctx, mgr, options)
6061
}
6162

@@ -66,8 +67,8 @@ type MachineReconciler struct {
6667
APIReader client.Reader
6768
Tracker *remote.ClusterCacheTracker
6869

69-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
70-
WatchFilterValue string
70+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
71+
WatchFilterPredicate predicates.LabelMatcher
7172

7273
// NodeDrainClientTimeout timeout of the client used for draining nodes.
7374
NodeDrainClientTimeout time.Duration
@@ -79,7 +80,7 @@ func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag
7980
UnstructuredCachingClient: r.UnstructuredCachingClient,
8081
APIReader: r.APIReader,
8182
Tracker: r.Tracker,
82-
WatchFilterValue: r.WatchFilterValue,
83+
WatchFilterPredicate: r.WatchFilterPredicate,
8384
NodeDrainClientTimeout: r.NodeDrainClientTimeout,
8485
}).SetupWithManager(ctx, mgr, options)
8586
}
@@ -91,8 +92,8 @@ type MachineSetReconciler struct {
9192
APIReader client.Reader
9293
Tracker *remote.ClusterCacheTracker
9394

94-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
95-
WatchFilterValue string
95+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
96+
WatchFilterPredicate predicates.LabelMatcher
9697
}
9798

9899
func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
@@ -101,7 +102,7 @@ func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
101102
UnstructuredCachingClient: r.UnstructuredCachingClient,
102103
APIReader: r.APIReader,
103104
Tracker: r.Tracker,
104-
WatchFilterValue: r.WatchFilterValue,
105+
WatchFilterPredicate: r.WatchFilterPredicate,
105106
}).SetupWithManager(ctx, mgr, options)
106107
}
107108

@@ -111,16 +112,16 @@ type MachineDeploymentReconciler struct {
111112
UnstructuredCachingClient client.Client
112113
APIReader client.Reader
113114

114-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
115-
WatchFilterValue string
115+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
116+
WatchFilterPredicate predicates.LabelMatcher
116117
}
117118

118119
func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
119120
return (&machinedeploymentcontroller.Reconciler{
120121
Client: r.Client,
121122
UnstructuredCachingClient: r.UnstructuredCachingClient,
122123
APIReader: r.APIReader,
123-
WatchFilterValue: r.WatchFilterValue,
124+
WatchFilterPredicate: r.WatchFilterPredicate,
124125
}).SetupWithManager(ctx, mgr, options)
125126
}
126127

@@ -129,15 +130,15 @@ type MachineHealthCheckReconciler struct {
129130
Client client.Client
130131
Tracker *remote.ClusterCacheTracker
131132

132-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
133-
WatchFilterValue string
133+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
134+
WatchFilterPredicate predicates.LabelMatcher
134135
}
135136

136137
func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
137138
return (&machinehealthcheckcontroller.Reconciler{
138-
Client: r.Client,
139-
Tracker: r.Tracker,
140-
WatchFilterValue: r.WatchFilterValue,
139+
Client: r.Client,
140+
Tracker: r.Tracker,
141+
WatchFilterPredicate: r.WatchFilterPredicate,
141142
}).SetupWithManager(ctx, mgr, options)
142143
}
143144

@@ -150,8 +151,8 @@ type ClusterTopologyReconciler struct {
150151

151152
RuntimeClient runtimeclient.Client
152153

153-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
154-
WatchFilterValue string
154+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
155+
WatchFilterPredicate predicates.LabelMatcher
155156

156157
// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
157158
// thus allowing to optimize reads for templates or provider specific objects in a managed topology.
@@ -164,7 +165,7 @@ func (r *ClusterTopologyReconciler) SetupWithManager(ctx context.Context, mgr ct
164165
APIReader: r.APIReader,
165166
RuntimeClient: r.RuntimeClient,
166167
UnstructuredCachingClient: r.UnstructuredCachingClient,
167-
WatchFilterValue: r.WatchFilterValue,
168+
WatchFilterPredicate: r.WatchFilterPredicate,
168169
}).SetupWithManager(ctx, mgr, options)
169170
}
170171

@@ -176,15 +177,15 @@ type MachineDeploymentTopologyReconciler struct {
176177
Client client.Client
177178
// APIReader is used to list MachineSets directly via the API server to avoid
178179
// race conditions caused by an outdated cache.
179-
APIReader client.Reader
180-
WatchFilterValue string
180+
APIReader client.Reader
181+
WatchFilterPredicate predicates.LabelMatcher
181182
}
182183

183184
func (r *MachineDeploymentTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
184185
return (&machinedeploymenttopologycontroller.Reconciler{
185-
Client: r.Client,
186-
APIReader: r.APIReader,
187-
WatchFilterValue: r.WatchFilterValue,
186+
Client: r.Client,
187+
APIReader: r.APIReader,
188+
WatchFilterPredicate: r.WatchFilterPredicate,
188189
}).SetupWithManager(ctx, mgr, options)
189190
}
190191

@@ -196,15 +197,15 @@ type MachineSetTopologyReconciler struct {
196197
Client client.Client
197198
// APIReader is used to list MachineSets directly via the API server to avoid
198199
// race conditions caused by an outdated cache.
199-
APIReader client.Reader
200-
WatchFilterValue string
200+
APIReader client.Reader
201+
WatchFilterPredicate predicates.LabelMatcher
201202
}
202203

203204
func (r *MachineSetTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
204205
return (&machinesettopologycontroller.Reconciler{
205-
Client: r.Client,
206-
APIReader: r.APIReader,
207-
WatchFilterValue: r.WatchFilterValue,
206+
Client: r.Client,
207+
APIReader: r.APIReader,
208+
WatchFilterPredicate: r.WatchFilterPredicate,
208209
}).SetupWithManager(ctx, mgr, options)
209210
}
210211

@@ -216,8 +217,8 @@ type ClusterClassReconciler struct {
216217
// RuntimeClient is a client for calling runtime extensions.
217218
RuntimeClient runtimeclient.Client
218219

219-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
220-
WatchFilterValue string
220+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
221+
WatchFilterPredicate predicates.LabelMatcher
221222

222223
// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
223224
// thus allowing to optimize reads for templates or provider specific objects.
@@ -230,6 +231,6 @@ func (r *ClusterClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
230231
APIReader: r.APIReader,
231232
RuntimeClient: r.RuntimeClient,
232233
UnstructuredCachingClient: r.UnstructuredCachingClient,
233-
WatchFilterValue: r.WatchFilterValue,
234+
WatchFilterPredicate: r.WatchFilterPredicate,
234235
}).SetupWithManager(ctx, mgr, options)
235236
}

controllers/remote/cluster_cache_reconciler.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ type ClusterCacheReconciler struct {
3636
Client client.Client
3737
Tracker *ClusterCacheTracker
3838

39-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
40-
WatchFilterValue string
39+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
40+
WatchFilterPredicate predicates.LabelMatcher
4141
}
4242

4343
func (r *ClusterCacheReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
4444
err := ctrl.NewControllerManagedBy(mgr).
4545
Named("remote/clustercache").
4646
For(&clusterv1.Cluster{}).
4747
WithOptions(options).
48-
WithEventFilter(predicates.GetExpressionMatcher().Matches(ctrl.LoggerFrom(ctx))).
49-
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
48+
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterPredicate)).
5049
Complete(r)
5150

5251
if err != nil {

controlplane/kubeadm/controllers/alias.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"sigs.k8s.io/cluster-api/controllers/remote"
2828
kubeadmcontrolplanecontrollers "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/controllers"
29+
"sigs.k8s.io/cluster-api/util/predicates"
2930
)
3031

3132
// KubeadmControlPlaneReconciler reconciles a KubeadmControlPlane object.
@@ -37,18 +38,18 @@ type KubeadmControlPlaneReconciler struct {
3738
EtcdDialTimeout time.Duration
3839
EtcdCallTimeout time.Duration
3940

40-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
41-
WatchFilterValue string
41+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
42+
WatchFilterPredicate predicates.LabelMatcher
4243
}
4344

4445
// SetupWithManager sets up the reconciler with the Manager.
4546
func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
4647
return (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
47-
Client: r.Client,
48-
SecretCachingClient: r.SecretCachingClient,
49-
Tracker: r.Tracker,
50-
EtcdDialTimeout: r.EtcdDialTimeout,
51-
EtcdCallTimeout: r.EtcdCallTimeout,
52-
WatchFilterValue: r.WatchFilterValue,
48+
Client: r.Client,
49+
SecretCachingClient: r.SecretCachingClient,
50+
Tracker: r.Tracker,
51+
EtcdDialTimeout: r.EtcdDialTimeout,
52+
EtcdCallTimeout: r.EtcdCallTimeout,
53+
WatchFilterPredicate: r.WatchFilterPredicate,
5354
}).SetupWithManager(ctx, mgr, options)
5455
}

controlplane/kubeadm/internal/controllers/controller.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ type KubeadmControlPlaneReconciler struct {
8080
EtcdDialTimeout time.Duration
8181
EtcdCallTimeout time.Duration
8282

83-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
84-
WatchFilterValue string
83+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
84+
WatchFilterPredicate predicates.LabelMatcher
8585

8686
managementCluster internal.ManagementCluster
8787
managementClusterUncached internal.ManagementCluster
@@ -99,15 +99,14 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
9999
For(&controlplanev1.KubeadmControlPlane{}).
100100
Owns(&clusterv1.Machine{}).
101101
WithOptions(options).
102-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
102+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterPredicate)).
103103
Watches(
104104
&clusterv1.Cluster{},
105105
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmControlPlane),
106106
builder.WithPredicates(
107107
predicates.All(ctrl.LoggerFrom(ctx),
108-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
108+
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterPredicate),
109109
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
110-
predicates.GetExpressionMatcher().Matches(ctrl.LoggerFrom(ctx)),
111110
),
112111
),
113112
).Build(r)

exp/addons/controllers/alias.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,37 @@ import (
2525

2626
"sigs.k8s.io/cluster-api/controllers/remote"
2727
clusterresourcesets "sigs.k8s.io/cluster-api/exp/addons/internal/controllers"
28+
"sigs.k8s.io/cluster-api/util/predicates"
2829
)
2930

3031
// ClusterResourceSetReconciler reconciles a ClusterResourceSet object.
3132
type ClusterResourceSetReconciler struct {
3233
Client client.Client
3334
Tracker *remote.ClusterCacheTracker
3435

35-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
36-
WatchFilterValue string
36+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
37+
WatchFilterPredicate predicates.LabelMatcher
3738
}
3839

3940
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
4041
return (&clusterresourcesets.ClusterResourceSetReconciler{
41-
Client: r.Client,
42-
Tracker: r.Tracker,
43-
WatchFilterValue: r.WatchFilterValue,
42+
Client: r.Client,
43+
Tracker: r.Tracker,
44+
WatchFilterPredicate: r.WatchFilterPredicate,
4445
}).SetupWithManager(ctx, mgr, options)
4546
}
4647

4748
// ClusterResourceSetBindingReconciler reconciles a ClusterResourceSetBinding object.
4849
type ClusterResourceSetBindingReconciler struct {
4950
Client client.Client
5051

51-
// WatchFilterValue is the label value used to filter events prior to reconciliation.
52-
WatchFilterValue string
52+
// WatchFilterPredicate is the label selector value used to filter events prior to reconciliation.
53+
WatchFilterPredicate predicates.LabelMatcher
5354
}
5455

5556
func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5657
return (&clusterresourcesets.ClusterResourceSetBindingReconciler{
57-
Client: r.Client,
58-
WatchFilterValue: r.WatchFilterValue,
58+
Client: r.Client,
59+
WatchFilterPredicate: r.WatchFilterPredicate,
5960
}).SetupWithManager(ctx, mgr, options)
6061
}

0 commit comments

Comments
 (0)