Skip to content

Commit 5d4f93c

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 cee1200 commit 5d4f93c

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

internal/controllers/machine/machine_controller_phases.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ 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+
if m.Status.Initialization == nil {
164+
m.Status.Initialization = &clusterv1.MachineInitializationStatus{}
165+
}
166+
m.Status.Initialization.BootstrapDataSecretCreated = true
167+
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyV1Beta1Condition)
168+
return true
169+
}
170+
return false
171+
}
172+
159173
// reconcileBootstrap reconciles the BootstrapConfig of a Machine.
160174
func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Result, error) {
161175
log := ctrl.LoggerFrom(ctx)
@@ -164,6 +178,8 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
164178

165179
// If the Bootstrap ref is nil (and so the machine should use user generated data secret), return.
166180
if m.Spec.Bootstrap.ConfigRef == nil {
181+
// If the bootstrap data is populated, set ready.
182+
_ = checkMachineBootstrapReady(m)
167183
return ctrl.Result{}, nil
168184
}
169185

@@ -187,12 +203,7 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, s *scope) (ctrl.Res
187203
s.bootstrapConfig = obj
188204

189205
// If the bootstrap data is populated, set ready and return.
190-
if m.Spec.Bootstrap.DataSecretName != nil {
191-
if m.Status.Initialization == nil {
192-
m.Status.Initialization = &clusterv1.MachineInitializationStatus{}
193-
}
194-
m.Status.Initialization.BootstrapDataSecretCreated = true
195-
v1beta1conditions.MarkTrue(m, clusterv1.BootstrapReadyV1Beta1Condition)
206+
if checkMachineBootstrapReady(m) {
196207
return ctrl.Result{}, nil
197208
}
198209

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.Initialization != nil && m.Status.Initialization.BootstrapDataSecretCreated).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+
Initialization: nil,
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.Initialization != nil && m.Status.Initialization.BootstrapDataSecretCreated).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)