Skip to content

Commit

Permalink
fix Cluster to AzureManagedControlPlane mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Jul 10, 2023
1 parent a32e1dc commit e82879f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion controllers/azuremanagedcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 (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
}

0 comments on commit e82879f

Please sign in to comment.