Skip to content

Commit e939503

Browse files
committed
Fix patching OpenstackMachine's immutable spec during reconcile
when the VM is vanished (cannot be fetched but existed at some point)
1 parent e590271 commit e939503

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

controllers/openstackmachine_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
329329
}
330330

331331
instanceStatus, err := r.getOrCreate(scope.Logger(), cluster, openStackCluster, machine, openStackMachine, computeService, userData)
332-
if err != nil {
332+
if err != nil || instanceStatus == nil {
333333
// Conditions set in getOrCreate
334334
return ctrl.Result{}, err
335335
}
@@ -439,6 +439,12 @@ func (r *OpenStackMachineReconciler) getOrCreate(logger logr.Logger, cluster *cl
439439
}
440440

441441
if instanceStatus == nil {
442+
if openStackMachine.Spec.InstanceID != nil {
443+
logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available")
444+
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists")
445+
openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists"))
446+
return nil, nil
447+
}
442448
instanceSpec := machineToInstanceSpec(openStackCluster, machine, openStackMachine, userData)
443449
logger.Info("Machine does not exist, creating Machine", "name", openStackMachine.Name)
444450
instanceStatus, err = computeService.CreateInstance(openStackMachine, openStackCluster, instanceSpec, cluster.Name)

0 commit comments

Comments
 (0)