Skip to content

Commit

Permalink
ensure machine power status is Off before making it available (ironco…
Browse files Browse the repository at this point in the history
…re-dev#123)

Signed-off-by: Artem Bortnikov <[email protected]>
  • Loading branch information
aobort authored Jun 14, 2024
1 parent 69e8ab0 commit 9de9c2d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/controller/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,20 @@ func (r *MachineReconciler) evaluateAvailability(
machine *metalv1alpha1.Machine,
machineStatusApply *metalv1alpha1apply.MachineStatusApplyConfiguration,
) {
idx := slices.IndexFunc(machineStatusApply.Conditions, func(c v1.ConditionApplyConfiguration) bool {
return *c.Type == MachineReadyConditionType
})
if *machineStatusApply.Conditions[idx].Status == metav1.ConditionFalse {
if !slices.ContainsFunc(machineStatusApply.Conditions, func(c v1.ConditionApplyConfiguration) bool {
return *c.Type == MachineReadyConditionType && *c.Status == metav1.ConditionTrue
}) {
return
}

if machine.Spec.MachineClaimRef != nil && machine.Spec.MachineClaimRef.Name != "" {
machineStatusApply.State = ptr.To(metalv1alpha1.MachineStateReserved)
} else {
return
}
if machine.Status.Power == metalv1alpha1.PowerOff {
machineStatusApply.State = ptr.To(metalv1alpha1.MachineStateAvailable)
} else {
machineStatusApply.State = ptr.To(machine.Status.State)
}
}

Expand Down

0 comments on commit 9de9c2d

Please sign in to comment.