From bed1b07d95222d30f6d03e2aa7cc141754e26493 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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/controllers/azuremanagedcontrolplane_controller.go b/controllers/azuremanagedcontrolplane_controller.go index 74bf627ec53..238e9274954 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,19 @@ 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 (amcpr *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 +}