mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
e2e: add test covering cronjob-scheduled-timestamp annotation added by cronjob
This commit is contained in:
parent
ae35048cb0
commit
f11ddad99d
@ -80,7 +80,7 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
|
||||
ginkgo.By("Ensuring at least two running jobs exists by listing jobs explicitly")
|
||||
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
|
||||
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
|
||||
activeJobs, _ := filterActiveJobs(jobs)
|
||||
gomega.Expect(len(activeJobs)).To(gomega.BeNumerically(">=", 2))
|
||||
|
||||
@ -109,7 +109,7 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
|
||||
ginkgo.By("Ensuring no job exists by listing jobs explicitly")
|
||||
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
|
||||
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
|
||||
gomega.Expect(jobs.Items).To(gomega.BeEmpty())
|
||||
|
||||
ginkgo.By("Removing cronjob")
|
||||
@ -140,7 +140,7 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
|
||||
ginkgo.By("Ensuring exactly one running job exists by listing jobs explicitly")
|
||||
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
|
||||
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
|
||||
activeJobs, _ := filterActiveJobs(jobs)
|
||||
gomega.Expect(activeJobs).To(gomega.HaveLen(1))
|
||||
|
||||
@ -213,7 +213,7 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
|
||||
ginkgo.By("Ensuring at least one running jobs exists by listing jobs explicitly")
|
||||
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
|
||||
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
|
||||
activeJobs, _ := filterActiveJobs(jobs)
|
||||
gomega.Expect(activeJobs).ToNot(gomega.BeEmpty())
|
||||
|
||||
@ -261,6 +261,31 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
|
||||
})
|
||||
|
||||
ginkgo.It("should set the cronjob-scheduled-timestamp annotation on a job", func(ctx context.Context) {
|
||||
ginkgo.By("Creating a cronjob")
|
||||
cronJob := newTestCronJob("concurrent", "*/1 * * * ?", batchv1.AllowConcurrent,
|
||||
nil, nil, nil)
|
||||
cronJob, err := createCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob)
|
||||
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
|
||||
|
||||
ginkgo.By("Ensuring CronJobsScheduledAnnotation annotation exists on the newely created job")
|
||||
err = waitForJobsAtLeast(ctx, f.ClientSet, f.Namespace.Name, 1)
|
||||
framework.ExpectNoError(err, "Failed to ensure a job exists in namespace %s", f.Namespace.Name)
|
||||
|
||||
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
|
||||
gomega.Expect(jobs.Items[0].Annotations).Should(gomega.HaveKey(batchv1.CronJobScheduledTimestampAnnotation),
|
||||
"missing cronjob-scheduled-timestamp annotation")
|
||||
ginkgo.By("Ensuring CronJobsScheduledAnnotation annotation parses to RFC3339")
|
||||
timeAnnotation := jobs.Items[0].Annotations[batchv1.CronJobScheduledTimestampAnnotation]
|
||||
_, err = time.Parse(time.RFC3339, timeAnnotation)
|
||||
framework.ExpectNoError(err, "Failed to parse cronjob-scheduled-timestamp annotation: %q", timeAnnotation)
|
||||
|
||||
ginkgo.By("Removing cronjob")
|
||||
err = deleteCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob.Name)
|
||||
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
|
||||
})
|
||||
|
||||
// deleted jobs should be removed from the active list
|
||||
ginkgo.It("should remove from active list jobs that have been deleted", func(ctx context.Context) {
|
||||
ginkgo.By("Creating a ForbidConcurrent cronjob")
|
||||
|
Loading…
Reference in New Issue
Block a user