Skip to content

Commit e81fc27

Browse files
ziock8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
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.
1 parent c170538 commit e81fc27

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

controllers/openstackmachine_controller.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -776,17 +776,22 @@ func (r *OpenStackMachineReconciler) getOrCreateInstance(logger logr.Logger, ope
776776
}
777777
if instanceStatus == nil {
778778
// Check if there is an existing instance with machine name, in case where instance ID would not have been stored in machine status
779-
if instanceStatus, err = computeService.GetInstanceStatusByName(openStackMachine, openStackMachine.Name); err == nil {
780-
if instanceStatus != nil {
781-
return instanceStatus, nil
782-
}
783-
if openStackMachine.Status.InstanceID != nil {
784-
logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available")
785-
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists")
786-
openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists"))
787-
return nil, nil
788-
}
779+
instanceStatus, err = computeService.GetInstanceStatusByName(openStackMachine, openStackMachine.Name)
780+
if err != nil {
781+
logger.Info("Unable to get OpenStack instance by name", "name", openStackMachine.Name)
782+
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceCreateFailedReason, clusterv1.ConditionSeverityError, err.Error())
783+
return nil, err
784+
}
785+
if instanceStatus != nil {
786+
return instanceStatus, nil
789787
}
788+
if openStackMachine.Status.InstanceID != nil {
789+
logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available")
790+
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists")
791+
openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists"))
792+
return nil, nil
793+
}
794+
790795
instanceSpec, err := machineToInstanceSpec(openStackCluster, machine, openStackMachine, userData)
791796
if err != nil {
792797
return nil, err

0 commit comments

Comments
 (0)