From e81fc275001df64da7df6cd87ea2f649939fd3f0 Mon Sep 17 00:00:00 2001 From: Francois Eleouet Date: Thu, 16 May 2024 10:14:19 +0200 Subject: [PATCH] Handle errors returned by GetInstanceStatusByName in machine controller These errors were ignored up to now, which could lead controller to attempt to recreate an existing instance under rare circumstances. --- controllers/openstackmachine_controller.go | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index ee923ec812..230ecd5342 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -776,17 +776,22 @@ func (r *OpenStackMachineReconciler) getOrCreateInstance(logger logr.Logger, ope } if instanceStatus == nil { // Check if there is an existing instance with machine name, in case where instance ID would not have been stored in machine status - if instanceStatus, err = computeService.GetInstanceStatusByName(openStackMachine, openStackMachine.Name); err == nil { - if instanceStatus != nil { - return instanceStatus, nil - } - if openStackMachine.Status.InstanceID != nil { - logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available") - conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists") - openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists")) - return nil, nil - } + instanceStatus, err = computeService.GetInstanceStatusByName(openStackMachine, openStackMachine.Name) + if err != nil { + logger.Info("Unable to get OpenStack instance by name", "name", openStackMachine.Name) + conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceCreateFailedReason, clusterv1.ConditionSeverityError, err.Error()) + return nil, err + } + if instanceStatus != nil { + return instanceStatus, nil } + if openStackMachine.Status.InstanceID != nil { + logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available") + conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists") + openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists")) + return nil, nil + } + instanceSpec, err := machineToInstanceSpec(openStackCluster, machine, openStackMachine, userData) if err != nil { return nil, err