@@ -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// ASOSecretReconciler reconciles ASO secrets associated with AzureCluster objects.
@@ -61,46 +61,36 @@ func (asos *ASOSecretReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
6161 )
6262 defer done ()
6363
64- c , err := ctrl .NewControllerManagedBy (mgr ).
64+ return ctrl .NewControllerManagedBy (mgr ).
6565 WithOptions (options ).
6666 For (& infrav1.AzureCluster {}).
6767 WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (log , asos .WatchFilterValue )).
6868 WithEventFilter (predicates .ResourceIsNotExternallyManaged (log )).
6969 Named ("ASOSecret" ).
7070 Owns (& corev1.Secret {}).
71- Build (asos )
72- if err != nil {
73- return errors .Wrap (err , "error creating controller" )
74- }
75-
76- // Add a watch on infrav1.AzureManagedControlPlane.
77- if err = c .Watch (
78- source .Kind (mgr .GetCache (), & infrav1.AzureManagedControlPlane {}),
79- & handler.EnqueueRequestForObject {},
80- predicates .ResourceNotPausedAndHasFilterLabel (log , asos .WatchFilterValue ),
81- ); err != nil {
82- return errors .Wrap (err , "failed adding a watch for ready AzureManagedControlPlanes" )
83- }
84-
85- // Add a watch on ASO secrets owned by an AzureManagedControlPlane
86- if err = c .Watch (
87- source .Kind (mgr .GetCache (), & corev1.Secret {}),
88- handler .EnqueueRequestForOwner (asos .Scheme (), asos .RESTMapper (), & infrav1.AzureManagedControlPlane {}, handler .OnlyControllerOwner ()),
89- ); err != nil {
90- return errors .Wrap (err , "failed adding a watch for secrets" )
91- }
92-
93- // Add a watch on clusterv1.Cluster object for unpause notifications.
94- if err = c .Watch (
95- source .Kind (mgr .GetCache (), & clusterv1.Cluster {}),
96- handler .EnqueueRequestsFromMapFunc (util .ClusterToInfrastructureMapFunc (ctx , infrav1 .GroupVersion .WithKind (infrav1 .AzureClusterKind ), mgr .GetClient (), & infrav1.AzureCluster {})),
97- predicates .ClusterUnpaused (log ),
98- predicates .ResourceNotPausedAndHasFilterLabel (log , asos .WatchFilterValue ),
99- ); err != nil {
100- return errors .Wrap (err , "failed adding a watch for ready clusters" )
101- }
102-
103- return nil
71+ // Add a watch on ASO secrets owned by an AzureManagedControlPlane
72+ Watches (
73+ & corev1.Secret {},
74+ handler .EnqueueRequestForOwner (asos .Scheme (), asos .RESTMapper (), & infrav1.AzureManagedControlPlane {}, handler .OnlyControllerOwner ()),
75+ ).
76+ // Add a watch on infrav1.AzureManagedControlPlane.
77+ Watches (
78+ & infrav1.AzureManagedControlPlane {},
79+ & handler.EnqueueRequestForObject {},
80+ builder .WithPredicates (
81+ predicates .ResourceNotPausedAndHasFilterLabel (log , asos .WatchFilterValue ),
82+ ),
83+ ).
84+ // Add a watch on clusterv1.Cluster object for unpause notifications.
85+ Watches (
86+ & clusterv1.Cluster {},
87+ handler .EnqueueRequestsFromMapFunc (util .ClusterToInfrastructureMapFunc (ctx , infrav1 .GroupVersion .WithKind (infrav1 .AzureClusterKind ), mgr .GetClient (), & infrav1.AzureCluster {})),
88+ builder .WithPredicates (
89+ predicates .ClusterUnpaused (log ),
90+ predicates .ResourceNotPausedAndHasFilterLabel (log , asos .WatchFilterValue ),
91+ ),
92+ ).
93+ Complete (asos )
10494}
10595
10696// Reconcile reconciles the ASO secrets associated with AzureCluster objects.
0 commit comments