Skip to content

Commit 1272d79

Browse files
committed
Watch Cluster pause transitions in ScalewayClusterReconciler
1 parent eaee670 commit 1272d79

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cmd/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ func main() {
164164
})
165165
}
166166

167+
ctx := ctrl.SetupSignalHandler()
168+
167169
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
168170
Scheme: scheme,
169171
Metrics: metricsServerOptions,
@@ -188,7 +190,7 @@ func main() {
188190
os.Exit(1)
189191
}
190192

191-
if err = controller.NewScalewayClusterReconciler(mgr.GetClient()).SetupWithManager(mgr); err != nil {
193+
if err = controller.NewScalewayClusterReconciler(mgr.GetClient()).SetupWithManager(ctx, mgr); err != nil {
192194
setupLog.Error(err, "unable to create controller", "controller", "ScalewayCluster")
193195
os.Exit(1)
194196
}
@@ -224,7 +226,7 @@ func main() {
224226
}
225227

226228
setupLog.Info("starting manager")
227-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
229+
if err := mgr.Start(ctx); err != nil {
228230
setupLog.Error(err, "problem running manager")
229231
os.Exit(1)
230232
}

internal/controller/scalewaycluster_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import (
77

88
corev1 "k8s.io/api/core/v1"
99
apierrors "k8s.io/apimachinery/pkg/api/errors"
10+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1011
"sigs.k8s.io/cluster-api/util"
1112
"sigs.k8s.io/cluster-api/util/annotations"
1213
"sigs.k8s.io/cluster-api/util/patch"
1314
"sigs.k8s.io/cluster-api/util/predicates"
1415
ctrl "sigs.k8s.io/controller-runtime"
16+
"sigs.k8s.io/controller-runtime/pkg/builder"
1517
"sigs.k8s.io/controller-runtime/pkg/client"
1618
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
1719
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
20+
"sigs.k8s.io/controller-runtime/pkg/handler"
1821
logf "sigs.k8s.io/controller-runtime/pkg/log"
1922

2023
infrav1 "github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1"
@@ -178,10 +181,16 @@ func (r *ScalewayClusterReconciler) reconcileNormal(ctx context.Context, cluster
178181
}
179182

180183
// SetupWithManager sets up the controller with the Manager.
181-
func (r *ScalewayClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
184+
func (r *ScalewayClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
182185
return ctrl.NewControllerManagedBy(mgr).
183186
For(&infrav1.ScalewayCluster{}).
184187
WithEventFilter(predicates.ResourceIsNotExternallyManaged(mgr.GetScheme(), mgr.GetLogger())).
188+
// Add a watch on clusterv1.Cluster object for pause/unpause notifications.
189+
Watches(
190+
&clusterv1.Cluster{},
191+
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("ScalewayCluster"), mgr.GetClient(), &infrav1.ScalewayCluster{})),
192+
builder.WithPredicates(predicates.ClusterPausedTransitions(mgr.GetScheme(), mgr.GetLogger())),
193+
).
185194
Named("scalewaycluster").
186195
Complete(r)
187196
}

0 commit comments

Comments
 (0)