From bbf49cd8fe77eb49a4e6851d466f81979cb9d04a Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Mon, 10 Jul 2023 17:48:39 -0500 Subject: [PATCH] fix Cluster to AzureManagedControlPlane mapper --- .../azuremanagedcontrolplane_controller.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/controllers/azuremanagedcontrolplane_controller.go b/controllers/azuremanagedcontrolplane_controller.go index 74bf627ec53..cbc2f2c35d0 100644 --- a/controllers/azuremanagedcontrolplane_controller.go +++ b/controllers/azuremanagedcontrolplane_controller.go @@ -98,7 +98,7 @@ func (amcpr *AzureManagedControlPlaneReconciler) SetupWithManager(ctx context.Co // Add a watch on clusterv1.Cluster object for unpause & ready notifications. if err = c.Watch( &source.Kind{Type: &clusterv1.Cluster{}}, - handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("AzureManagedControlPlane"), mgr.GetClient(), &infrav1.AzureManagedControlPlane{})), + handler.EnqueueRequestsFromMapFunc(amcpr.ClusterToAzureManagedControlPlane), predicates.ClusterUnpausedAndInfrastructureReady(log), predicates.ResourceNotPausedAndHasFilterLabel(log, amcpr.WatchFilterValue), ); err != nil { @@ -295,3 +295,20 @@ func (amcpr *AzureManagedControlPlaneReconciler) reconcileDelete(ctx context.Con return reconcile.Result{}, nil } + +// ClusterToAzureManagedControlPlane is a handler.ToRequestsFunc to be used to enqueue requests for +// reconciliation for AzureManagedControlPlane based on updates to a Cluster. +func (r *AzureManagedControlPlaneReconciler) ClusterToAzureManagedControlPlane(o client.Object) (reqs []ctrl.Request) { + c, ok := o.(*clusterv1.Cluster) + if !ok { + panic(fmt.Sprintf("Expected a Cluster but got a %T", o)) + } + + controlPlaneRef := c.Spec.ControlPlaneRef + if controlPlaneRef != nil && controlPlaneRef.Kind == "AzureManagedControlPlane" { + + return []ctrl.Request{{NamespacedName: client.ObjectKey{Namespace: controlPlaneRef.Namespace, Name: controlPlaneRef.Name}}} + } + + return nil +}