From 68763b7dc5b6ad7e02d45289c2e5e2c6d1cf3cf2 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Fri, 9 Dec 2022 13:23:11 +0000 Subject: [PATCH] Allow Machines in unreachable Clusters to do initial reconciliation Signed-off-by: killianmuldoon --- internal/controllers/machine/machine_controller.go | 4 ---- internal/controllers/machine/machine_controller_noderef.go | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index f32f1b7d4b1a..7afb763fb772 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -267,10 +267,6 @@ func patchMachine(ctx context.Context, patchHelper *patch.Helper, machine *clust } func (r *Reconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster, m *clusterv1.Machine) (ctrl.Result, error) { - if err := r.watchClusterNodes(ctx, cluster); err != nil { - return ctrl.Result{}, err - } - // If the machine is a stand-alone one, meaning not originated from a MachineDeployment, then set it as directly // owned by the Cluster (if not already present). if r.shouldAdopt(m) { diff --git a/internal/controllers/machine/machine_controller_noderef.go b/internal/controllers/machine/machine_controller_noderef.go index 29b5a397679f..d18047ebf14e 100644 --- a/internal/controllers/machine/machine_controller_noderef.go +++ b/internal/controllers/machine/machine_controller_noderef.go @@ -44,6 +44,11 @@ var ( func (r *Reconciler) reconcileNode(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) + // Create a watch on the nodes in the Cluster. + if err := r.watchClusterNodes(ctx, cluster); err != nil { + return ctrl.Result{}, err + } + // Check that the Machine has a valid ProviderID. if machine.Spec.ProviderID == nil || *machine.Spec.ProviderID == "" { log.Info("Waiting for infrastructure provider to report spec.providerID", machine.Spec.InfrastructureRef.Kind, klog.KRef(machine.Spec.InfrastructureRef.Namespace, machine.Spec.InfrastructureRef.Name))