@@ -143,6 +143,8 @@ func (r *MetalStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
143143 statusErr := reconciler .status ()
144144 if statusErr != nil {
145145 err = errors .Join (err , fmt .Errorf ("unable to update status: %w" , statusErr ))
146+ } else if ! reconciler .infraMachine .Status .Ready {
147+ err = errors .New ("machine is not yet ready, requeueing" )
146148 }
147149 }()
148150
@@ -188,6 +190,10 @@ func (r *MetalStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
188190 return ctrl.Result {}, errors .New ("waiting until control plane ip was set to cluster spec" )
189191 }
190192
193+ if machine .Spec .Bootstrap .DataSecretName == nil {
194+ return ctrl.Result {}, errors .New ("waiting until bootstrap data secret was created" )
195+ }
196+
191197 err = reconciler .reconcile ()
192198
193199 return ctrl.Result {}, err // remember to return err here and not nil because the defer func can influence this
@@ -256,6 +262,17 @@ func (r *machineReconciler) delete() error {
256262}
257263
258264func (r * machineReconciler ) create () (* models.V1MachineResponse , error ) {
265+ bootstrapSecret := & corev1.Secret {
266+ ObjectMeta : metav1.ObjectMeta {
267+ Name : * r .clusterMachine .Spec .Bootstrap .DataSecretName ,
268+ Namespace : r .infraMachine .Namespace ,
269+ },
270+ }
271+ err := r .client .Get (r .ctx , client .ObjectKeyFromObject (bootstrapSecret ), bootstrapSecret )
272+ if err != nil {
273+ return nil , fmt .Errorf ("unable to fetch bootstrap secret: %w" , err )
274+ }
275+
259276 var (
260277 ips []string
261278 nws = []* models.V1MachineAllocationNetwork {
@@ -292,7 +309,8 @@ func (r *machineReconciler) create() (*models.V1MachineResponse, error) {
292309 Description : fmt .Sprintf ("%s/%s for cluster %s/%s" , r .infraMachine .Namespace , r .infraMachine .Name , r .infraCluster .Namespace , r .infraCluster .Name ),
293310 Networks : nws ,
294311 Ips : ips ,
295- // TODO: UserData, SSHPubKeys, ...
312+ UserData : string (bootstrapSecret .Data ["value" ]),
313+ // TODO: SSHPubKeys, ...
296314 }), nil )
297315 if err != nil {
298316 return nil , fmt .Errorf ("failed to allocate machine: %w" , err )
@@ -330,9 +348,11 @@ func (r *machineReconciler) status() error {
330348 case err != nil && ! errors .Is (err , errProviderMachineNotFound ):
331349 conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineCreated , "InternalError" , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
332350 conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineHealthy , "NotHealthy" , clusterv1 .ConditionSeverityWarning , "machine not created" )
351+ conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineReady , "NotReady" , clusterv1 .ConditionSeverityWarning , "machine not created" )
333352 case err != nil && errors .Is (err , errProviderMachineNotFound ):
334353 conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineCreated , "NotCreated" , clusterv1 .ConditionSeverityError , "%s" , err .Error ())
335354 conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineHealthy , "NotHealthy" , clusterv1 .ConditionSeverityWarning , "machine not created" )
355+ conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineReady , "NotReady" , clusterv1 .ConditionSeverityWarning , "machine not created" )
336356 default :
337357 if r .infraMachine .Spec .ProviderID == * m .ID {
338358 conditions .MarkTrue (r .infraMachine , v1alpha1 .ProviderMachineCreated )
@@ -357,6 +377,12 @@ func (r *machineReconciler) status() error {
357377 }
358378 }
359379
380+ if m .Events != nil && len (m .Events .Log ) > 0 && ptr .Deref (m .Events .Log [0 ].Event , "" ) == "Phoned Home" {
381+ conditions .MarkTrue (r .infraMachine , v1alpha1 .ProviderMachineReady )
382+ } else {
383+ conditions .MarkFalse (r .infraMachine , v1alpha1 .ProviderMachineReady , "NotReady" , clusterv1 .ConditionSeverityWarning , "machine is not in phoned home state" )
384+ }
385+
360386 if len (errs ) == 0 {
361387 conditions .MarkTrue (r .infraMachine , v1alpha1 .ProviderMachineHealthy )
362388 } else {
0 commit comments