From f74c2e3ad9e52526841a59e35e38518e239bd7fd Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 14 Nov 2024 17:03:50 +1300 Subject: [PATCH] Set Machine's BootstrapReady when there is no ConfigRef If there is no ConfigRef but the bootstrap data secret is set by the user (instead of a bootstrap provider), then BootstrapReady should be true. This is the case for MachineSet, and was originally the case for Machine since 5113f801f130f2d8f0a1b90403b7d868c696c1b8. However, in d93eadcbc06ad6ef5131e2a6df1673be4397e525 this changed as a side effect of ensuring that bootstrap config object can continue to be reconciled after the bootstrap provider has produced the bootstrap data secret. This change ensures that, once a bootstrap data secret exists, in the case of a ConfigRef it can still be reconciled, while in the case there is no ConfigRef, BootstrapReady is set. Signed-off-by: Zane Bitter --- .../machine/machine_controller_phases.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/controllers/machine/machine_controller_phases.go b/internal/controllers/machine/machine_controller_phases.go index f7e53d0ce232..fa411a7bf823 100644 --- a/internal/controllers/machine/machine_controller_phases.go +++ b/internal/controllers/machine/machine_controller_phases.go @@ -126,6 +126,17 @@ func (r *Reconciler) ensureExternalOwnershipAndWatch(ctx context.Context, cluste return obj, nil } +// checkMachineBootstrapReady checks if the bootstrap data for a Machine is +// available and marks it as ready if so. +func checkMachineBootstrapReady(m *clusterv1.Machine) bool { + if m.Spec.Bootstrap.DataSecretName != nil { + m.Status.BootstrapReady = true + conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition) + return true + } + return false +} + // reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a Machine. func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) @@ -134,6 +145,8 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res // If the Bootstrap ref is nil (and so the machine should use user generated data secret), return. if m.Spec.Bootstrap.ConfigRef == nil { + // If the bootstrap data is populated, set ready. + _ = checkMachineBootstrapReady(m) return ctrl.Result{}, nil } @@ -157,9 +170,7 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res s.bootstrapConfig = obj // If the bootstrap data is populated, set ready and return. - if m.Spec.Bootstrap.DataSecretName != nil { - m.Status.BootstrapReady = true - conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition) + if checkMachineBootstrapReady(m) { return ctrl.Result{}, nil }