Add e2e test for backoffLimitPerIndex

This commit is contained in:
Michal Wozniak 2023-10-19 17:18:30 +02:00
parent 3e438c54a7
commit b06675724d
2 changed files with 40 additions and 0 deletions

View File

@ -380,6 +380,36 @@ var _ = SIGDescribe("Job", func() {
gomega.Expect(gotIndexes).To(gomega.Equal(wantIndexes), "expected completed indexes %s, but got %s", wantIndexes, gotIndexes)
})
/*
Testcase: Ensure that all indexes are executed for an indexed job with backoffLimitPerIndex despite some failing
Description: Create an indexed job and ensure that all indexes are either failed or succeeded, depending
on the end state of the corresponding pods. Pods with odd indexes fail, while the pods with even indexes
succeeded. Also, verify that the number of failed pods doubles the number of failing indexes, as the
backoffLimitPerIndex=1, allowing for one pod recreation before marking that indexed failed.
*/
ginkgo.It("should execute all indexes despite some failing when using backoffLimitPerIndex", func(ctx context.Context) {
ginkgo.By("Creating an indexed job with backoffLimit per index and failing pods")
job := e2ejob.NewTestJob("failOddSucceedEven", "with-backoff-limit-per-index", v1.RestartPolicyNever, parallelism, completions, nil, backoffLimit)
job.Spec.BackoffLimit = nil
job.Spec.BackoffLimitPerIndex = ptr.To[int32](1)
mode := batchv1.IndexedCompletion
job.Spec.CompletionMode = &mode
job, err := e2ejob.CreateJob(ctx, f.ClientSet, f.Namespace.Name, job)
framework.ExpectNoError(err, "failed to create job in namespace: %s", f.Namespace.Name)
ginkgo.By("Awaiting for the job to fail as there are failed indexes")
err = e2ejob.WaitForJobFailed(f.ClientSet, f.Namespace.Name, job.Name)
framework.ExpectNoError(err, "failed to ensure job completion in namespace: %s", f.Namespace.Name)
ginkgo.By("Verifying the Job status fields to ensure all indexes were executed")
job, err = e2ejob.GetJob(ctx, f.ClientSet, f.Namespace.Name, job.Name)
framework.ExpectNoError(err, "failed to retrieve latest job object")
gomega.Expect(job.Status.FailedIndexes).Should(gomega.HaveValue(gomega.Equal("1,3")))
gomega.Expect(job.Status.CompletedIndexes).Should(gomega.Equal("0,2"))
gomega.Expect(job.Status.Failed).Should(gomega.Equal(int32(4)))
gomega.Expect(job.Status.Succeeded).Should(gomega.Equal(int32(2)))
})
/*
Testcase: Ensure that the pods associated with the job are removed once the job is deleted
Description: Create a job and ensure the associated pod count is equal to parallelism count. Delete the

View File

@ -90,6 +90,16 @@ func NewTestJobOnNode(behavior, name string, rPol v1.RestartPolicy, parallelism,
job.Spec.Template.Spec.Containers[0].Command = []string{"sleep", "1000000"}
case "fail":
job.Spec.Template.Spec.Containers[0].Command = []string{"/bin/sh", "-c", "exit 1"}
case "failOddSucceedEven":
job.Spec.Template.Spec.Containers[0].Command = []string{"sh", "-c"}
job.Spec.Template.Spec.Containers[0].Args = []string{`
if [ $(expr ${JOB_COMPLETION_INDEX} % 2) -ne 0 ]; then
exit 1
else
exit 0
fi
`,
}
case "succeed":
job.Spec.Template.Spec.Containers[0].Command = []string{"/bin/sh", "-c", "exit 0"}
case "randomlySucceedOrFail":