From b0e96add95a8a9d7d4d4b83ef7e5d730bba4050e Mon Sep 17 00:00:00 2001 From: Enxebre Date: Wed, 8 Sep 2021 18:40:32 +0200 Subject: [PATCH] Add watches for infras and control plane in topology controller Fixes https://github.com/kubernetes-sigs/cluster-api/issues/5194 --- controllers/topology/cluster_controller.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/controllers/topology/cluster_controller.go b/controllers/topology/cluster_controller.go index 57f6b4bb5007..5fffab34850e 100644 --- a/controllers/topology/cluster_controller.go +++ b/controllers/topology/cluster_controller.go @@ -142,6 +142,20 @@ func (r *ClusterReconciler) reconcile(ctx context.Context, s *scope.Scope) (ctrl return ctrl.Result{}, errors.Wrap(err, "error reading current state of the Cluster topology") } + // Watch Infrastructure and ControlPlane CRs when they exist. + if s.Current.InfrastructureCluster != nil { + if err := r.externalTracker.Watch(ctrl.LoggerFrom(ctx), s.Current.InfrastructureCluster, + &handler.EnqueueRequestForOwner{OwnerType: &clusterv1.Cluster{}}); err != nil { + return ctrl.Result{}, errors.Wrap(err, "error watching Infrastructure CR") + } + } + if s.Current.ControlPlane.Object != nil { + if err := r.externalTracker.Watch(ctrl.LoggerFrom(ctx), s.Current.ControlPlane.Object, + &handler.EnqueueRequestForOwner{OwnerType: &clusterv1.Cluster{}}); err != nil { + return ctrl.Result{}, errors.Wrap(err, "error watching ControlPlane CR") + } + } + // Computes the desired state of the Cluster and store it in the request scope. s.Desired, err = r.computeDesiredState(ctx, s) if err != nil {