Do not preallocate node for Job e2e tests to fix flakes

This commit is contained in:
Michal Wozniak 2023-10-24 14:23:16 +02:00
parent 8453eb0c24
commit 69ca55f136

View File

@ -80,11 +80,15 @@ func NewTestJobOnNode(behavior, name string, rPol v1.RestartPolicy, parallelism,
SecurityContext: &v1.SecurityContext{}, SecurityContext: &v1.SecurityContext{},
}, },
}, },
NodeName: nodeName,
}, },
}, },
}, },
} }
if len(nodeName) > 0 {
job.Spec.Template.Spec.NodeSelector = map[string]string{
"kubernetes.io/hostname": nodeName,
}
}
switch behavior { switch behavior {
case "notTerminate": case "notTerminate":
job.Spec.Template.Spec.Containers[0].Command = []string{"sleep", "1000000"} 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 // setup host path directory to pass information between pod restarts
func setupHostPathDirectory(job *batchv1.Job) { 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) randomDir := "/tmp/job-e2e/" + rand.String(10)
hostPathType := v1.HostPathDirectoryOrCreate hostPathType := v1.HostPathDirectoryOrCreate
job.Spec.Template.Spec.Volumes[0].VolumeSource = v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: randomDir, Type: &hostPathType}} job.Spec.Template.Spec.Volumes[0].VolumeSource = v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{Path: randomDir, Type: &hostPathType}}