From f472e1a6949b4db78944ab8bab05b519487a71af Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Wed, 18 Dec 2024 17:56:21 +0100 Subject: [PATCH] Perform draining and volume detaching once until completion Signed-off-by: Danil-Grigorev --- .../controllers/machine/machine_controller.go | 8 ++++ .../machine/machine_controller_test.go | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index fe98ab3436dd..4d08017b9898 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -657,6 +657,10 @@ func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool { return false } + if conditions.IsTrue(m, clusterv1.DrainingSucceededCondition) { + return false + } + return true } @@ -677,6 +681,10 @@ func (r *Reconciler) isNodeVolumeDetachingAllowed(m *clusterv1.Machine) bool { return false } + if conditions.IsTrue(m, clusterv1.VolumeDetachSucceededCondition) { + return false + } + return true } diff --git a/internal/controllers/machine/machine_controller_test.go b/internal/controllers/machine/machine_controller_test.go index 373a5b0053df..5383cee792fe 100644 --- a/internal/controllers/machine/machine_controller_test.go +++ b/internal/controllers/machine/machine_controller_test.go @@ -1428,6 +1428,28 @@ func TestIsNodeDrainedAllowed(t *testing.T) { }, expected: false, }, + { + name: "Node draining succeeded", + machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-machine", + Namespace: metav1.NamespaceDefault, + Finalizers: []string{clusterv1.MachineFinalizer}, + }, + Spec: clusterv1.MachineSpec{ + ClusterName: "test-cluster", + InfrastructureRef: corev1.ObjectReference{}, + Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, + }, + Status: clusterv1.MachineStatus{ + Conditions: clusterv1.Conditions{{ + Type: clusterv1.DrainingSucceededCondition, + Status: corev1.ConditionTrue, + }}, + }, + }, + expected: false, + }, { name: "Node draining timeout is not yet over", machine: &clusterv1.Machine{ @@ -1989,6 +2011,28 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) { }, expected: false, }, + { + name: "Volume detach completed", + machine: &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-machine", + Namespace: metav1.NamespaceDefault, + Finalizers: []string{clusterv1.MachineFinalizer}, + }, + Spec: clusterv1.MachineSpec{ + ClusterName: "test-cluster", + InfrastructureRef: corev1.ObjectReference{}, + Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, + }, + Status: clusterv1.MachineStatus{ + Conditions: clusterv1.Conditions{{ + Type: clusterv1.VolumeDetachSucceededCondition, + Status: corev1.ConditionTrue, + }}, + }, + }, + expected: false, + }, { name: "Volume detach timeout is not yet over", machine: &clusterv1.Machine{