Skip to content

Commit ab7948c

Browse files
authored
Merge pull request #11776 from jakefhyde/11775-check-machinepool-feature-gate-for-cluster
🐛 Check machinepool feature-flag before watching in cluster controller
2 parents 010af7f + a5010bd commit ab7948c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/controllers/cluster/cluster_controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
9696
}
9797

9898
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster")
99-
c, err := ctrl.NewControllerManagedBy(mgr).
99+
b := ctrl.NewControllerManagedBy(mgr).
100100
For(&clusterv1.Cluster{}).
101101
WatchesRawSource(r.ClusterCache.GetClusterSource("cluster", func(_ context.Context, o client.Object) []ctrl.Request {
102102
return []ctrl.Request{{NamespacedName: client.ObjectKeyFromObject(o)}}
@@ -110,12 +110,16 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
110110
&clusterv1.MachineDeployment{},
111111
handler.EnqueueRequestsFromMapFunc(r.machineDeploymentToCluster),
112112
builder.WithPredicates(predicates.ResourceIsChanged(mgr.GetScheme(), predicateLog)),
113-
).
114-
Watches(
113+
)
114+
if feature.Gates.Enabled(feature.MachinePool) {
115+
b = b.Watches(
115116
&expv1.MachinePool{},
116117
handler.EnqueueRequestsFromMapFunc(r.machinePoolToCluster),
117118
builder.WithPredicates(predicates.ResourceIsChanged(mgr.GetScheme(), predicateLog)),
118-
).
119+
)
120+
}
121+
122+
c, err := b.
119123
WithOptions(options).
120124
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
121125
Build(r)

0 commit comments

Comments
 (0)