Skip to content

Commit 0967466

Browse files
authored
Merge pull request kubernetes-sigs#4830 from CecileRobertMichon/drain-timeout-interval
🌱 Make node drain delete timeout configurable in e2e framework
2 parents 59c620c + 6973ec1 commit 0967466

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

test/e2e/config/docker.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ intervals:
128128
default/wait-machine-remediation: ["5m", "10s"]
129129
node-drain/wait-deployment-available: ["3m", "10s"]
130130
node-drain/wait-control-plane: ["15m", "10s"]
131+
node-drain/wait-machine-deleted: ["2m", "10s"]

test/e2e/node_drain_timeout.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
6666
Expect(os.MkdirAll(input.ArtifactFolder, 0755)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)
6767

6868
Expect(input.E2EConfig.GetIntervals(specName, "wait-deployment-available")).ToNot(BeNil())
69+
Expect(input.E2EConfig.GetIntervals(specName, "wait-machine-deleted")).ToNot(BeNil())
6970

7071
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
7172
namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder)
@@ -109,7 +110,7 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
109110

110111
By("Scale the machinedeployment down to zero. If we didn't have the NodeDrainTimeout duration, the node drain process would block this operator.")
111112
// Because all the machines of a machinedeployment can be deleted at the same time, so we only prepare the interval for 1 replica.
112-
nodeDrainTimeoutMachineDeploymentInterval := convertDurationToInterval(machineDeployments[0].Spec.Template.Spec.NodeDrainTimeout, 1)
113+
nodeDrainTimeoutMachineDeploymentInterval := getDrainAndDeleteInterval(input.E2EConfig.GetIntervals(specName, "wait-machine-deleted"), machineDeployments[0].Spec.Template.Spec.NodeDrainTimeout, 1)
113114
for _, md := range machineDeployments {
114115
framework.ScaleAndWaitMachineDeployment(ctx, framework.ScaleAndWaitMachineDeploymentInput{
115116
ClusterProxy: input.BootstrapClusterProxy,
@@ -131,7 +132,7 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
131132

132133
By("Scale down the controlplane of the workload cluster and make sure that nodes running workload can be deleted even the draining process is blocked.")
133134
// When we scale down the KCP, controlplane machines are by default deleted one by one, so it requires more time.
134-
nodeDrainTimeoutKCPInterval := convertDurationToInterval(controlplane.Spec.MachineTemplate.NodeDrainTimeout, controlPlaneReplicas)
135+
nodeDrainTimeoutKCPInterval := getDrainAndDeleteInterval(input.E2EConfig.GetIntervals(specName, "wait-machine-deleted"), controlplane.Spec.MachineTemplate.NodeDrainTimeout, controlPlaneReplicas)
135136
framework.ScaleAndWaitControlPlane(ctx, framework.ScaleAndWaitControlPlaneInput{
136137
ClusterProxy: input.BootstrapClusterProxy,
137138
Cluster: cluster,
@@ -149,10 +150,11 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
149150
})
150151
}
151152

152-
func convertDurationToInterval(duration *metav1.Duration, replicas int) []interface{} {
153-
pollingInterval := time.Second * 10
154-
// After the drain timeout is over, the cluster still needs more time to completely delete the machine, that why we need an extra 2-minute amount of time.
155-
intervalDuration := (duration.Duration + time.Minute*2) * time.Duration(replicas)
156-
res := []interface{}{intervalDuration.String(), pollingInterval.String()}
153+
func getDrainAndDeleteInterval(deleteInterval []interface{}, drainTimeout *metav1.Duration, replicas int) []interface{} {
154+
deleteTimeout, err := time.ParseDuration(deleteInterval[0].(string))
155+
Expect(err).NotTo(HaveOccurred())
156+
// We add the drain timeout to the specified delete timeout per replica.
157+
intervalDuration := (drainTimeout.Duration + deleteTimeout) * time.Duration(replicas)
158+
res := []interface{}{intervalDuration.String(), deleteInterval[1]}
157159
return res
158160
}

0 commit comments

Comments
 (0)