Skip to content

🐛 Set Machine's BootstrapReady when there is no ConfigRef #11459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions internal/controllers/machine/machine_controller_phases.go
Original file line number Diff line number Diff line change
@@ -156,6 +156,20 @@ 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 {
if m.Status.Initialization == nil {
m.Status.Initialization = &clusterv1.MachineInitializationStatus{}
}
m.Status.Initialization.BootstrapDataSecretCreated = true
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyV1Beta1Condition)
return true
}
return false
}

// reconcileBootstrap reconciles the BootstrapConfig of a Machine.
func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
@@ -164,6 +178,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
}

@@ -187,12 +203,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 {
if m.Status.Initialization == nil {
m.Status.Initialization = &clusterv1.MachineInitializationStatus{}
}
m.Status.Initialization.BootstrapDataSecretCreated = true
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyV1Beta1Condition)
if checkMachineBootstrapReady(m) {
return ctrl.Result{}, nil
}

27 changes: 27 additions & 0 deletions internal/controllers/machine/machine_controller_phases_test.go
Original file line number Diff line number Diff line change
@@ -112,6 +112,33 @@ func TestReconcileBootstrap(t *testing.T) {
g.Expect(m.Status.Initialization != nil && m.Status.Initialization.BootstrapDataSecretCreated).To(BeFalse())
},
},
{
name: "bootstrap data ready with no bootstrap config",
contract: "v1beta1",
machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "bootstrap-test-external",
Namespace: metav1.NamespaceDefault,
},
Spec: clusterv1.MachineSpec{
Bootstrap: clusterv1.Bootstrap{
DataSecretName: ptr.To("secret-data"),
},
},
Status: clusterv1.MachineStatus{
Initialization: nil,
},
},
bootstrapConfig: nil,
bootstrapConfigGetError: errors.New("this should not happen"),
expectResult: ctrl.Result{},
expectError: false,
expected: func(g *WithT, m *clusterv1.Machine) {
g.Expect(m.Status.Initialization != nil && m.Status.Initialization.BootstrapDataSecretCreated).To(BeTrue())
g.Expect(m.Spec.Bootstrap.DataSecretName).NotTo(BeNil())
g.Expect(*m.Spec.Bootstrap.DataSecretName).To(Equal("secret-data"))
},
},
{
name: "bootstrap config not ready, it should reconcile but no data should surface on the machine",
contract: "v1beta1",