Skip to content

Commit c140ed1

Browse files
committed
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 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]>
1 parent 129b395 commit c140ed1

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

internal/controllers/machine/machine_controller_phases.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ func (r *Reconciler) ensureExternalOwnershipAndWatch(ctx context.Context, cluste
143143
return obj, nil
144144
}
145145

146+
// checkMachineBootstrapReady checks if the bootstrap data for a Machine is
147+
// available and marks it as ready if so.
148+
func checkMachineBootstrapReady(m *clusterv1.Machine) bool {
149+
if m.Spec.Bootstrap.DataSecretName != nil {
150+
m.Status.BootstrapReady = true
151+
conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
152+
return true
153+
}
154+
return false
155+
}
156+
146157
// reconcileBootstrap reconciles the Spec.Bootstrap.ConfigRef object on a Machine.
147158
func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) {
148159
log := ctrl.LoggerFrom(ctx)
@@ -151,6 +162,8 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
151162

152163
// If the Bootstrap ref is nil (and so the machine should use user generated data secret), return.
153164
if m.Spec.Bootstrap.ConfigRef == nil {
165+
// If the bootstrap data is populated, set ready.
166+
_ = checkMachineBootstrapReady(m)
154167
return ctrl.Result{}, nil
155168
}
156169

@@ -174,9 +187,7 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
174187
s.bootstrapConfig = obj
175188

176189
// If the bootstrap data is populated, set ready and return.
177-
if m.Spec.Bootstrap.DataSecretName != nil {
178-
m.Status.BootstrapReady = true
179-
conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
190+
if checkMachineBootstrapReady(m) {
180191
return ctrl.Result{}, nil
181192
}
182193

internal/controllers/machine/machine_controller_phases_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ func TestReconcileBootstrap(t *testing.T) {
107107
g.Expect(m.Status.BootstrapReady).To(BeFalse())
108108
},
109109
},
110+
{
111+
name: "bootstrap data ready with no bootstrap config",
112+
machine: &clusterv1.Machine{
113+
ObjectMeta: metav1.ObjectMeta{
114+
Name: "bootstrap-test-external",
115+
Namespace: metav1.NamespaceDefault,
116+
},
117+
Spec: clusterv1.MachineSpec{
118+
Bootstrap: clusterv1.Bootstrap{
119+
DataSecretName: ptr.To("secret-data"),
120+
},
121+
},
122+
Status: clusterv1.MachineStatus{
123+
BootstrapReady: false,
124+
},
125+
},
126+
bootstrapConfig: nil,
127+
bootstrapConfigGetError: errors.New("this should not happen"),
128+
expectResult: ctrl.Result{},
129+
expectError: false,
130+
expected: func(g *WithT, m *clusterv1.Machine) {
131+
g.Expect(m.Status.BootstrapReady).To(BeTrue())
132+
g.Expect(m.Spec.Bootstrap.DataSecretName).NotTo(BeNil())
133+
g.Expect(*m.Spec.Bootstrap.DataSecretName).To(Equal("secret-data"))
134+
},
135+
},
110136
{
111137
name: "bootstrap config not ready, it should reconcile but no data should surface on the machine",
112138
machine: defaultMachine.DeepCopy(),

0 commit comments

Comments
 (0)