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 11, 2023
1 parent a32e1dc commit bed1b07
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 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,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))

Check warning on line 304 in controllers/azuremanagedcontrolplane_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_controller.go#L301-L304

Added lines #L301 - L304 were not covered by tests
}

controlPlaneRef := c.Spec.ControlPlaneRef
if controlPlaneRef != nil && controlPlaneRef.Kind == "AzureManagedControlPlane" {
return []ctrl.Request{{NamespacedName: client.ObjectKey{Namespace: controlPlaneRef.Namespace, Name: controlPlaneRef.Name}}}
}

Check warning on line 310 in controllers/azuremanagedcontrolplane_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_controller.go#L307-L310

Added lines #L307 - L310 were not covered by tests

return nil

Check warning on line 312 in controllers/azuremanagedcontrolplane_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_controller.go#L312

Added line #L312 was not covered by tests
}

0 comments on commit bed1b07

Please sign in to comment.