Skip to content

Commit

Permalink
Set Machine's BootstrapReady when there is no ConfigRef
Browse files Browse the repository at this point in the history
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 5113f80. However, in
d93eadc 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 <[email protected]>
  • Loading branch information
zaneb committed Nov 28, 2024
1 parent 5bd7ded commit f74c2e3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/controllers/machine/machine_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit f74c2e3

Please sign in to comment.