@@ -34,6 +34,7 @@ import (
3434 csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
3535 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3636 "sigs.k8s.io/cluster-api/util"
37+ "sigs.k8s.io/cluster-api/util/predicates"
3738)
3839
3940// RBAC permissions used in all reconcilers. Events and Secrets.
@@ -156,6 +157,8 @@ func (r *CloudStackClusterReconciliationRunner) ReconcileDelete() (ctrl.Result,
156157
157158// Called in main, this registers the cluster reconciler to the CAPI controller manager.
158159func (reconciler * CloudStackClusterReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , opts controller.Options ) error {
160+ log := ctrl .LoggerFrom (ctx )
161+
159162 controller , err := ctrl .NewControllerManagedBy (mgr ).
160163 WithOptions (opts ).
161164 For (& infrav1.CloudStackCluster {}).
@@ -186,18 +189,14 @@ func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Cont
186189 }
187190
188191 // Add a watch on CAPI Cluster objects for unpause and ready events.
189- err = controller .Watch (
192+ if err = controller .Watch (
190193 & source.Kind {Type : & clusterv1.Cluster {}},
191194 handler .EnqueueRequestsFromMapFunc (
192195 util .ClusterToInfrastructureMapFunc (ctx , infrav1 .GroupVersion .WithKind ("CloudStackCluster" ), mgr .GetClient (), & infrav1.CloudStackCluster {})),
193- predicate.Funcs {
194- UpdateFunc : func (e event.UpdateEvent ) bool {
195- oldCluster := e .ObjectOld .(* clusterv1.Cluster )
196- newCluster := e .ObjectNew .(* clusterv1.Cluster )
197- return oldCluster .Spec .Paused && ! newCluster .Spec .Paused
198- },
199- DeleteFunc : func (e event.DeleteEvent ) bool { return false },
200- CreateFunc : func (e event.CreateEvent ) bool { return false },
201- })
202- return errors .Wrap (err , "building CloudStackCluster controller" )
196+ predicates .ClusterUnpaused (log ),
197+ ); err != nil {
198+ return errors .Wrap (err , "building CloudStackCluster controller" )
199+ }
200+
201+ return nil
203202}
0 commit comments