From 69ca55f136835c8467adec519deb5e647ea0ac13 Mon Sep 17 00:00:00 2001 From: Michal Wozniak Date: Tue, 24 Oct 2023 14:23:16 +0200 Subject: [PATCH] Do not preallocate node for Job e2e tests to fix flakes --- test/e2e/framework/job/fixtures.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/job/fixtures.go b/test/e2e/framework/job/fixtures.go index ca0f6af8b28..036758dfb13 100644 --- a/test/e2e/framework/job/fixtures.go +++ b/test/e2e/framework/job/fixtures.go @@ -80,11 +80,15 @@ func NewTestJobOnNode(behavior, name string, rPol v1.RestartPolicy, parallelism, SecurityContext: &v1.SecurityContext{}, }, }, - NodeName: nodeName, }, }, }, } + if len(nodeName) > 0 { + job.Spec.Template.Spec.NodeSelector = map[string]string{ + "kubernetes.io/hostname": nodeName, + } + } switch behavior { case "notTerminate": job.Spec.Template.Spec.Containers[0].Command = []string{"sleep", "1000000"} @@ -119,7 +123,7 @@ func NewTestJobOnNode(behavior, name string, rPol v1.RestartPolicy, parallelism, // setup host path directory to pass information between pod restarts func setupHostPathDirectory(job *batchv1.Job) { - if len(job.Spec.Template.Spec.NodeName) > 0 { + if _, nodeNameSpecified := job.Spec.Template.Spec.NodeSelector["kubernetes.io/hostname"]; nodeNameSpecified { randomDir := "/tmp/job-e2e/" + rand.String(10) hostPathType := v1.HostPathDirectoryOrCreate job.Spec.Template.Spec.Volumes[0].VolumeSource = v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: randomDir, Type: &hostPathType}}