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 14, 2024
1 parent 5bd7ded commit 8ebd235
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions internal/controllers/machine/machine_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,26 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
cluster := s.cluster
m := s.machine

// If the Bootstrap ref is nil (and so the machine should use user generated data secret), return.
if m.Spec.Bootstrap.ConfigRef == nil {
return ctrl.Result{}, nil
}

// Call generic external reconciler if we have an external reference.
obj, err := r.reconcileExternal(ctx, cluster, m, m.Spec.Bootstrap.ConfigRef)
if err != nil {
if apierrors.IsNotFound(err) {
s.bootstrapConfigIsNotFound = true

if !s.machine.DeletionTimestamp.IsZero() {
// Tolerate bootstrap object not found when the machine is being deleted.
// TODO: we can also relax this and tolerate the absence of the bootstrap ref way before, e.g. after node ref is set
return ctrl.Result{}, nil
if m.Spec.Bootstrap.ConfigRef != nil {
// Call generic external reconciler if we have an external reference.
obj, err := r.reconcileExternal(ctx, cluster, m, m.Spec.Bootstrap.ConfigRef)
if err != nil {
if apierrors.IsNotFound(err) {
s.bootstrapConfigIsNotFound = true

if !s.machine.DeletionTimestamp.IsZero() {
// Tolerate bootstrap object not found when the machine is being deleted.
// TODO: we can also relax this and tolerate the absence of the bootstrap ref way before, e.g. after node ref is set
return ctrl.Result{}, nil
}
log.Info("Could not find bootstrap config object, requeuing", m.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(m.Spec.Bootstrap.ConfigRef.Namespace, m.Spec.Bootstrap.ConfigRef.Name))
// TODO: we can make this smarter and requeue only if we are before node ref is set
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
}
log.Info("Could not find bootstrap config object, requeuing", m.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(m.Spec.Bootstrap.ConfigRef.Namespace, m.Spec.Bootstrap.ConfigRef.Name))
// TODO: we can make this smarter and requeue only if we are before node ref is set
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
return ctrl.Result{}, err
}
return ctrl.Result{}, err
s.bootstrapConfig = obj
}
s.bootstrapConfig = obj

// If the bootstrap data is populated, set ready and return.
if m.Spec.Bootstrap.DataSecretName != nil {
Expand All @@ -163,6 +160,11 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
return ctrl.Result{}, nil
}

// If the Bootstrap ref is nil (and so the machine should use user generated data secret), return.
if m.Spec.Bootstrap.ConfigRef == nil {
return ctrl.Result{}, nil
}

// Determine if the bootstrap provider is ready.
ready, err := external.IsReady(s.bootstrapConfig)
if err != nil {
Expand Down

0 comments on commit 8ebd235

Please sign in to comment.