@@ -38,11 +38,11 @@ import (
3838 "sigs.k8s.io/cluster-api/util/annotations"
3939 "sigs.k8s.io/cluster-api/util/predicates"
4040 ctrl "sigs.k8s.io/controller-runtime"
41+ "sigs.k8s.io/controller-runtime/pkg/builder"
4142 "sigs.k8s.io/controller-runtime/pkg/client"
4243 "sigs.k8s.io/controller-runtime/pkg/controller"
4344 "sigs.k8s.io/controller-runtime/pkg/handler"
4445 "sigs.k8s.io/controller-runtime/pkg/reconcile"
45- "sigs.k8s.io/controller-runtime/pkg/source"
4646)
4747
4848// AzureJSONTemplateReconciler reconciles Azure json secrets for AzureMachineTemplate objects.
@@ -65,29 +65,22 @@ func (r *AzureJSONTemplateReconciler) SetupWithManager(ctx context.Context, mgr
6565 return errors .Wrap (err , "failed to create mapper for Cluster to AzureMachineTemplates" )
6666 }
6767
68- c , err := ctrl .NewControllerManagedBy (mgr ).
68+ return ctrl .NewControllerManagedBy (mgr ).
6969 WithOptions (options ).
7070 For (& infrav1.AzureMachineTemplate {}).
7171 WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (log , r .WatchFilterValue )).
7272 Owns (& corev1.Secret {}).
73- Build (r )
74-
75- if err != nil {
76- return errors .Wrap (err , "failed to create controller" )
77- }
78-
79- // Add a watch on Clusters to requeue when the infraRef is set. This is needed because the infraRef is not initially
80- // set in Clusters created from a ClusterClass.
81- if err := c .Watch (
82- source .Kind (mgr .GetCache (), & clusterv1.Cluster {}),
83- handler .EnqueueRequestsFromMapFunc (azureMachineTemplateMapper ),
84- predicates .ClusterUnpausedAndInfrastructureReady (log ),
85- predicates .ResourceNotPausedAndHasFilterLabel (log , r .WatchFilterValue ),
86- ); err != nil {
87- return errors .Wrap (err , "failed adding a watch for Clusters" )
88- }
89-
90- return nil
73+ // Add a watch on Clusters to requeue when the infraRef is set. This is needed because the infraRef is not initially
74+ // set in Clusters created from a ClusterClass.
75+ Watches (
76+ & clusterv1.Cluster {},
77+ handler .EnqueueRequestsFromMapFunc (azureMachineTemplateMapper ),
78+ builder .WithPredicates (
79+ predicates .ClusterUnpausedAndInfrastructureReady (log ),
80+ predicates .ResourceNotPausedAndHasFilterLabel (log , r .WatchFilterValue ),
81+ ),
82+ ).
83+ Complete (r )
9184}
9285
9386// Reconcile reconciles Azure json secrets for Azure machine templates.
0 commit comments