Skip to content

Commit

Permalink
Perform draining and volume detaching once until completion
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Dec 18, 2024
1 parent 8b08484 commit f472e1a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
return false
}

if conditions.IsTrue(m, clusterv1.DrainingSucceededCondition) {
return false
}

return true
}

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

if conditions.IsTrue(m, clusterv1.VolumeDetachSucceededCondition) {
return false
}

return true
}

Expand Down
44 changes: 44 additions & 0 deletions internal/controllers/machine/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit f472e1a

Please sign in to comment.