From 190cb7779c9c64017ea6b696c1f8157c81885035 Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Fri, 14 Jun 2024 15:21:13 +0200 Subject: [PATCH] Ensure unhealthy machines get deletion priority --- .../machineset/machineset_delete_policy.go | 4 ++++ .../machineset_delete_policy_test.go | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/controllers/machineset/machineset_delete_policy.go b/internal/controllers/machineset/machineset_delete_policy.go index 4e029659f27f..9ad2beb99890 100644 --- a/internal/controllers/machineset/machineset_delete_policy.go +++ b/internal/controllers/machineset/machineset_delete_policy.go @@ -150,5 +150,9 @@ func isMachineHealthy(machine *clusterv1.Machine) bool { if nodeHealthyCondition != nil && nodeHealthyCondition.Status != corev1.ConditionTrue { return false } + healthCheckCondition := conditions.Get(machine, clusterv1.MachineHealthCheckSucceededCondition) + if healthCheckCondition != nil && healthCheckCondition.Status == corev1.ConditionFalse { + return false + } return true } diff --git a/internal/controllers/machineset/machineset_delete_policy_test.go b/internal/controllers/machineset/machineset_delete_policy_test.go index 2dee46ac37e6..024599c75123 100644 --- a/internal/controllers/machineset/machineset_delete_policy_test.go +++ b/internal/controllers/machineset/machineset_delete_policy_test.go @@ -68,6 +68,17 @@ func TestMachineToDelete(t *testing.T) { }, }, } + healthyCheckConditionFalseMachine := &clusterv1.Machine{ + Status: clusterv1.MachineStatus{ + NodeRef: nodeRef, + Conditions: clusterv1.Conditions{ + { + Type: clusterv1.MachineHealthCheckSucceededCondition, + Status: corev1.ConditionFalse, + }, + }, + }, + } tests := []struct { desc string @@ -222,6 +233,18 @@ func TestMachineToDelete(t *testing.T) { nodeHealthyConditionUnknownMachine, }, }, + { + desc: "func=randomDeletePolicy, NodeHealthyConditionFalseMachine, diff=1", + diff: 1, + machines: []*clusterv1.Machine{ + healthyMachine, + healthyCheckConditionFalseMachine, + healthyMachine, + }, + expect: []*clusterv1.Machine{ + healthyCheckConditionFalseMachine, + }, + }, } for _, test := range tests {