diff --git a/pkg/framework/framework.go b/pkg/framework/framework.go index dad3a6f57..f11c5f838 100644 --- a/pkg/framework/framework.go +++ b/pkg/framework/framework.go @@ -36,6 +36,7 @@ const ( // if MachineSet.Spec.Replicas field is set to nil DefaultMachineSetReplicas = 0 MachinePhaseRunning = "Running" + MachinePhaseFailed = "Failed" MachineRoleLabel = "machine.openshift.io/cluster-api-machine-role" MachineTypeLabel = "machine.openshift.io/cluster-api-machine-type" MachineAnnotationKey = "machine.openshift.io/machine" diff --git a/pkg/framework/machines.go b/pkg/framework/machines.go index 6091133ce..bcbd2face 100644 --- a/pkg/framework/machines.go +++ b/pkg/framework/machines.go @@ -20,17 +20,23 @@ import ( ) // FilterRunningMachines returns a slice of only those Machines in the input -// that are in the "Running" phase. -func FilterRunningMachines(machines []*mapiv1beta1.Machine) []*mapiv1beta1.Machine { +// that are in the "Running" phase. If some of the machine enters Failed phase, +// it will indicate this wil an error. +func FilterRunningMachines(machines []*mapiv1beta1.Machine) ([]*mapiv1beta1.Machine, error) { var result []*mapiv1beta1.Machine for i, m := range machines { - if m.Status.Phase != nil && *m.Status.Phase == MachinePhaseRunning { - result = append(result, machines[i]) + if m.Status.Phase != nil { + switch *m.Status.Phase { + case MachinePhaseRunning: + result = append(result, machines[i]) + case MachinePhaseFailed: + return nil, fmt.Errorf("Machine entered the Failed phase: %q, reason: %v", m.GetName(), m.Status.ErrorMessage) + } } } - return result + return result, nil } // GetMachine get a machine by its name from the default machine API namespace. diff --git a/pkg/framework/machinesets.go b/pkg/framework/machinesets.go index a2b649b10..30b298844 100644 --- a/pkg/framework/machinesets.go +++ b/pkg/framework/machinesets.go @@ -312,7 +312,8 @@ func WaitForMachineSet(c client.Client, name string) { name, len(machines), int(replicas)) } - running := FilterRunningMachines(machines) + running, err := FilterRunningMachines(machines) + Expect(err).ToNot(HaveOccurred()) // This could probably be smarter, but seems fine for now. if len(running) != len(machines) { diff --git a/pkg/infra/webhooks.go b/pkg/infra/webhooks.go index eddf2a3ab..ad28136c2 100644 --- a/pkg/infra/webhooks.go +++ b/pkg/infra/webhooks.go @@ -85,7 +85,8 @@ var _ = Describe("[Feature:Machines] Webhooks", func() { if err != nil { return err } - running := framework.FilterRunningMachines([]*mapiv1.Machine{m}) + running, err := framework.FilterRunningMachines([]*mapiv1.Machine{m}) + Expect(err).ToNot(HaveOccurred()) if len(running) == 0 { return fmt.Errorf("machine not yet running") }