Merge pull request #86348 from soltysh/issue86179

Split cronjob tests, so they don't interfere
This commit is contained in:
Kubernetes Prow Robot 2019-12-17 19:48:21 -08:00 committed by GitHub
commit fc1824fadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,71 +229,70 @@ var _ = SIGDescribe("CronJob", func() {
framework.ExpectNoError(err, "Failed to remove %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name) framework.ExpectNoError(err, "Failed to remove %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
}) })
// cleanup of successful/failed finished jobs, with successfulJobsHistoryLimit and failedJobsHistoryLimit // cleanup of successful finished jobs, with limit of one successful job
ginkgo.It("should delete successful/failed finished jobs with limit of one job [Flaky]", func() { ginkgo.It("should delete successful finished jobs with limit of one successful job", func() {
ginkgo.By("Creating an AllowConcurrent cronjob with custom history limit")
successLimit := int32(1)
failedLimit := int32(0)
cronJob := newTestCronJob("successful-jobs-history-limit", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
successCommand, &successLimit, &failedLimit)
testCases := []struct { ensureHistoryLimits(f.ClientSet, f.Namespace.Name, cronJob)
description string })
command []string
successLimit int32
failedLimit int32
}{
{
description: "successful-jobs-history-limit",
command: successCommand,
successLimit: 1, // keep one successful job
failedLimit: 0, // keep none failed job
},
{
description: "failed-jobs-history-limit",
command: failureCommand,
successLimit: 0, // keep none succcessful job
failedLimit: 1, // keep one failed job
},
}
for _, t := range testCases { // cleanup of failed finished jobs, with limit of one failed job
ginkgo.By(fmt.Sprintf("Creating a AllowConcurrent cronjob with custom %s", t.description)) ginkgo.It("should delete failed finished jobs with limit of one job", func() {
cronJob := newTestCronJob(t.description, "*/1 * * * ?", batchv1beta1.AllowConcurrent, ginkgo.By("Creating an AllowConcurrent cronjob with custom history limit")
t.command, &t.successLimit, &t.failedLimit) successLimit := int32(0)
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob) failedLimit := int32(1)
framework.ExpectNoError(err, "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", f.Namespace.Name) cronJob := newTestCronJob("failed-jobs-history-limit", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
failureCommand, &successLimit, &failedLimit)
ensureHistoryLimits(f.ClientSet, f.Namespace.Name, cronJob)
})
})
func ensureHistoryLimits(c clientset.Interface, ns string, cronJob *batchv1beta1.CronJob) {
cronJob, err := createCronJob(c, ns, cronJob)
framework.ExpectNoError(err, "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", ns)
// Job is going to complete instantly: do not check for an active job // Job is going to complete instantly: do not check for an active job
// as we are most likely to miss it // as we are most likely to miss it
ginkgo.By("Ensuring a finished job exists") ginkgo.By("Ensuring a finished job exists")
err = waitForAnyFinishedJob(f.ClientSet, f.Namespace.Name) err = waitForAnyFinishedJob(c, ns)
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists in namespace %s", f.Namespace.Name) framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists in namespace %s", ns)
ginkgo.By("Ensuring a finished job exists by listing jobs explicitly") ginkgo.By("Ensuring a finished job exists by listing jobs explicitly")
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{}) jobs, err := c.BatchV1().Jobs(ns).List(metav1.ListOptions{})
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", f.Namespace.Name) framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", ns)
activeJobs, finishedJobs := filterActiveJobs(jobs) activeJobs, finishedJobs := filterActiveJobs(jobs)
if len(finishedJobs) != 1 { if len(finishedJobs) != 1 {
framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", f.Namespace.Name, activeJobs, finishedJobs) framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", ns, activeJobs, finishedJobs)
framework.ExpectEqual(len(finishedJobs), 1) framework.ExpectEqual(len(finishedJobs), 1)
} }
// Job should get deleted when the next job finishes the next minute // Job should get deleted when the next job finishes the next minute
ginkgo.By("Ensuring this job and its pods does not exist anymore") ginkgo.By("Ensuring this job and its pods does not exist anymore")
err = waitForJobToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0]) err = waitForJobToDisappear(c, ns, finishedJobs[0])
framework.ExpectNoError(err, "Failed to ensure that job does not exists anymore in namespace %s", f.Namespace.Name) framework.ExpectNoError(err, "Failed to ensure that job does not exists anymore in namespace %s", ns)
err = waitForJobsPodToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0]) err = waitForJobsPodToDisappear(c, ns, finishedJobs[0])
framework.ExpectNoError(err, "Failed to ensure that pods for job does not exists anymore in namespace %s", f.Namespace.Name) framework.ExpectNoError(err, "Failed to ensure that pods for job does not exists anymore in namespace %s", ns)
ginkgo.By("Ensuring there is 1 finished job by listing jobs explicitly") ginkgo.By("Ensuring there is 1 finished job by listing jobs explicitly")
jobs, err = f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{}) jobs, err = c.BatchV1().Jobs(ns).List(metav1.ListOptions{})
framework.ExpectNoError(err, "Failed to ensure there is one finished job by listing job explicitly in namespace %s", f.Namespace.Name) framework.ExpectNoError(err, "Failed to ensure there is one finished job by listing job explicitly in namespace %s", ns)
_, finishedJobs = filterActiveJobs(jobs) activeJobs, finishedJobs = filterActiveJobs(jobs)
if len(finishedJobs) != 1 {
framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", ns, activeJobs, finishedJobs)
framework.ExpectEqual(len(finishedJobs), 1) framework.ExpectEqual(len(finishedJobs), 1)
}
ginkgo.By("Removing cronjob") ginkgo.By("Removing cronjob")
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name) err = deleteCronJob(c, ns, cronJob.Name)
framework.ExpectNoError(err, "Failed to remove the %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name) framework.ExpectNoError(err, "Failed to remove the %s cronjob in namespace %s", cronJob.Name, ns)
} }
})
})
// newTestCronJob returns a cronjob which does one of several testing behaviors. // newTestCronJob returns a cronjob which does one of several testing behaviors.
func newTestCronJob(name, schedule string, concurrencyPolicy batchv1beta1.ConcurrencyPolicy, func newTestCronJob(name, schedule string, concurrencyPolicy batchv1beta1.ConcurrencyPolicy,