Skip to content

Commit af1823a

Browse files
committed
Update MachinePool bootstrap dataSecretName when bootstrap config changes
1 parent 7f5b475 commit af1823a

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

exp/internal/controllers/machinepool_controller_phases.go

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -197,48 +197,51 @@ func (r *MachinePoolReconciler) reconcileBootstrap(ctx context.Context, cluster
197197
return ctrl.Result{}, nil
198198
}
199199
bootstrapConfig = bootstrapReconcileResult.Result
200-
}
201200

202-
// If the bootstrap data secret is populated, set ready and return.
203-
if m.Spec.Template.Spec.Bootstrap.DataSecretName != nil {
204-
m.Status.BootstrapReady = true
205-
conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
206-
return ctrl.Result{}, nil
207-
}
201+
// If the bootstrap config is being deleted, return early.
202+
if !bootstrapConfig.GetDeletionTimestamp().IsZero() {
203+
return ctrl.Result{}, nil
204+
}
208205

209-
// If the bootstrap config is being deleted, return early.
210-
if !bootstrapConfig.GetDeletionTimestamp().IsZero() {
211-
return ctrl.Result{}, nil
212-
}
206+
// Determine if the bootstrap provider is ready.
207+
ready, err := external.IsReady(bootstrapConfig)
208+
if err != nil {
209+
return ctrl.Result{}, err
210+
}
213211

214-
// Determine if the bootstrap provider is ready.
215-
ready, err := external.IsReady(bootstrapConfig)
216-
if err != nil {
217-
return ctrl.Result{}, err
218-
}
212+
// Report a summary of current status of the bootstrap object defined for this machine pool.
213+
conditions.SetMirror(m, clusterv1.BootstrapReadyCondition,
214+
conditions.UnstructuredGetter(bootstrapConfig),
215+
conditions.WithFallbackValue(ready, clusterv1.WaitingForDataSecretFallbackReason, clusterv1.ConditionSeverityInfo, ""),
216+
)
219217

220-
// Report a summary of current status of the bootstrap object defined for this machine pool.
221-
conditions.SetMirror(m, clusterv1.BootstrapReadyCondition,
222-
conditions.UnstructuredGetter(bootstrapConfig),
223-
conditions.WithFallbackValue(ready, clusterv1.WaitingForDataSecretFallbackReason, clusterv1.ConditionSeverityInfo, ""),
224-
)
218+
if !ready {
219+
log.V(2).Info("Bootstrap provider is not ready, requeuing")
220+
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
221+
}
225222

226-
if !ready {
227-
log.V(2).Info("Bootstrap provider is not ready, requeuing")
228-
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
223+
// Get and set the name of the secret containing the bootstrap data.
224+
secretName, _, err := unstructured.NestedString(bootstrapConfig.Object, "status", "dataSecretName")
225+
if err != nil {
226+
return ctrl.Result{}, errors.Wrapf(err, "failed to retrieve dataSecretName from bootstrap provider for MachinePool %q in namespace %q", m.Name, m.Namespace)
227+
} else if secretName == "" {
228+
return ctrl.Result{}, errors.Errorf("retrieved empty dataSecretName from bootstrap provider for MachinePool %q in namespace %q", m.Name, m.Namespace)
229+
}
230+
231+
m.Spec.Template.Spec.Bootstrap.DataSecretName = pointer.String(secretName)
232+
m.Status.BootstrapReady = true
233+
return ctrl.Result{}, nil
229234
}
230235

231-
// Get and set the name of the secret containing the bootstrap data.
232-
secretName, _, err := unstructured.NestedString(bootstrapConfig.Object, "status", "dataSecretName")
233-
if err != nil {
234-
return ctrl.Result{}, errors.Wrapf(err, "failed to retrieve dataSecretName from bootstrap provider for MachinePool %q in namespace %q", m.Name, m.Namespace)
235-
} else if secretName == "" {
236-
return ctrl.Result{}, errors.Errorf("retrieved empty dataSecretName from bootstrap provider for MachinePool %q in namespace %q", m.Name, m.Namespace)
236+
// If dataSecretName is set without a ConfigRef, this means the user brought their own bootstrap data.
237+
if m.Spec.Template.Spec.Bootstrap.DataSecretName != nil {
238+
m.Status.BootstrapReady = true
239+
conditions.MarkTrue(m, clusterv1.BootstrapReadyCondition)
240+
return ctrl.Result{}, nil
237241
}
238242

239-
m.Spec.Template.Spec.Bootstrap.DataSecretName = pointer.String(secretName)
240-
m.Status.BootstrapReady = true
241-
return ctrl.Result{}, nil
243+
// Return error if neither ConfigRef nor DataSecretName are set.
244+
return ctrl.Result{}, errors.Errorf("neither .spec.bootstrap.configRef nor .spec.bootstrap.dataSecretName are set for MachinePool %q in namespace %q", m.Name, m.Namespace)
242245
}
243246

244247
// reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a MachinePool.

0 commit comments

Comments
 (0)