Skip to content

Commit f472e1a

Browse files
Perform draining and volume detaching once until completion
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
1 parent 8b08484 commit f472e1a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

internal/controllers/machine/machine_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
657657
return false
658658
}
659659

660+
if conditions.IsTrue(m, clusterv1.DrainingSucceededCondition) {
661+
return false
662+
}
663+
660664
return true
661665
}
662666

@@ -677,6 +681,10 @@ func (r *Reconciler) isNodeVolumeDetachingAllowed(m *clusterv1.Machine) bool {
677681
return false
678682
}
679683

684+
if conditions.IsTrue(m, clusterv1.VolumeDetachSucceededCondition) {
685+
return false
686+
}
687+
680688
return true
681689
}
682690

internal/controllers/machine/machine_controller_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,28 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
14281428
},
14291429
expected: false,
14301430
},
1431+
{
1432+
name: "Node draining succeeded",
1433+
machine: &clusterv1.Machine{
1434+
ObjectMeta: metav1.ObjectMeta{
1435+
Name: "test-machine",
1436+
Namespace: metav1.NamespaceDefault,
1437+
Finalizers: []string{clusterv1.MachineFinalizer},
1438+
},
1439+
Spec: clusterv1.MachineSpec{
1440+
ClusterName: "test-cluster",
1441+
InfrastructureRef: corev1.ObjectReference{},
1442+
Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")},
1443+
},
1444+
Status: clusterv1.MachineStatus{
1445+
Conditions: clusterv1.Conditions{{
1446+
Type: clusterv1.DrainingSucceededCondition,
1447+
Status: corev1.ConditionTrue,
1448+
}},
1449+
},
1450+
},
1451+
expected: false,
1452+
},
14311453
{
14321454
name: "Node draining timeout is not yet over",
14331455
machine: &clusterv1.Machine{
@@ -1989,6 +2011,28 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
19892011
},
19902012
expected: false,
19912013
},
2014+
{
2015+
name: "Volume detach completed",
2016+
machine: &clusterv1.Machine{
2017+
ObjectMeta: metav1.ObjectMeta{
2018+
Name: "test-machine",
2019+
Namespace: metav1.NamespaceDefault,
2020+
Finalizers: []string{clusterv1.MachineFinalizer},
2021+
},
2022+
Spec: clusterv1.MachineSpec{
2023+
ClusterName: "test-cluster",
2024+
InfrastructureRef: corev1.ObjectReference{},
2025+
Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")},
2026+
},
2027+
Status: clusterv1.MachineStatus{
2028+
Conditions: clusterv1.Conditions{{
2029+
Type: clusterv1.VolumeDetachSucceededCondition,
2030+
Status: corev1.ConditionTrue,
2031+
}},
2032+
},
2033+
},
2034+
expected: false,
2035+
},
19922036
{
19932037
name: "Volume detach timeout is not yet over",
19942038
machine: &clusterv1.Machine{

0 commit comments

Comments
 (0)