Skip to content

Commit

Permalink
Merge pull request #2087 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2086-to-release-0.10

[release-0.10] 🐛 Handle errors returned by GetInstanceStatusByName in machine controller
  • Loading branch information
k8s-ci-robot authored May 16, 2024
2 parents c170538 + e81fc27 commit a0432a8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0432a8

Please sign in to comment.