Skip to content

Commit 4fdde8d

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 e389055 commit 4fdde8d

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

internal/controllers/machine/machine_controller_phases.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ func (r *Reconciler) ensureExternalOwnershipAndWatch(ctx context.Context, cluste
156156
return obj, nil
157157
}
158158

159+
// checkMachineBootstrapReady checks if the bootstrap data for a Machine is
160+
// available and marks it as ready if so.
161+
func checkMachineBootstrapReady(m *clusterv1.Machine) bool {
162+
if m.Spec.Bootstrap.DataSecretName != nil {
163+
m.Status.BootstrapReady = true
164+
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
165+
return true
166+
}
167+
return false
168+
}
169+
159170
// reconcileBootstrap reconciles the BootstrapConfig of a Machine.
160171
func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) {
161172
log := ctrl.LoggerFrom(ctx)
@@ -164,6 +175,8 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
164175

165176
// If the Bootstrap ref is nil (and so the machine should use user generated data secret), return.
166177
if m.Spec.Bootstrap.ConfigRef == nil {
178+
// If the bootstrap data is populated, set ready.
179+
_ = checkMachineBootstrapReady(m)
167180
return ctrl.Result{}, nil
168181
}
169182

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

189202
// If the bootstrap data is populated, set ready and return.
190-
if m.Spec.Bootstrap.DataSecretName != nil {
191-
m.Status.BootstrapReady = true
192-
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
203+
if checkMachineBootstrapReady(m) {
193204
return ctrl.Result{}, nil
194205
}
195206

internal/controllers/machine/machine_controller_phases_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ func TestReconcileBootstrap(t *testing.T) {
112112
g.Expect(m.Status.BootstrapReady).To(BeFalse())
113113
},
114114
},
115+
{
116+
name: "bootstrap data ready with no bootstrap config",
117+
contract: "v1beta1",
118+
machine: &clusterv1.Machine{
119+
ObjectMeta: metav1.ObjectMeta{
120+
Name: "bootstrap-test-external",
121+
Namespace: metav1.NamespaceDefault,
122+
},
123+
Spec: clusterv1.MachineSpec{
124+
Bootstrap: clusterv1.Bootstrap{
125+
DataSecretName: ptr.To("secret-data"),
126+
},
127+
},
128+
Status: clusterv1.MachineStatus{
129+
BootstrapReady: false,
130+
},
131+
},
132+
bootstrapConfig: nil,
133+
bootstrapConfigGetError: errors.New("this should not happen"),
134+
expectResult: ctrl.Result{},
135+
expectError: false,
136+
expected: func(g *WithT, m *clusterv1.Machine) {
137+
g.Expect(m.Status.BootstrapReady).To(BeTrue())
138+
g.Expect(m.Spec.Bootstrap.DataSecretName).NotTo(BeNil())
139+
g.Expect(*m.Spec.Bootstrap.DataSecretName).To(Equal("secret-data"))
140+
},
141+
},
115142
{
116143
name: "bootstrap config not ready, it should reconcile but no data should surface on the machine",
117144
contract: "v1beta1",

0 commit comments

Comments
 (0)