Skip to content

Commit f11ddad

Browse files
committed
e2e: add test covering cronjob-scheduled-timestamp annotation added by cronjob
1 parent ae35048 commit f11ddad

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

test/e2e/apps/cronjob.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var _ = SIGDescribe("CronJob", func() {
8080

8181
ginkgo.By("Ensuring at least two running jobs exists by listing jobs explicitly")
8282
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
83-
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
83+
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
8484
activeJobs, _ := filterActiveJobs(jobs)
8585
gomega.Expect(len(activeJobs)).To(gomega.BeNumerically(">=", 2))
8686

@@ -109,7 +109,7 @@ var _ = SIGDescribe("CronJob", func() {
109109

110110
ginkgo.By("Ensuring no job exists by listing jobs explicitly")
111111
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
112-
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
112+
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
113113
gomega.Expect(jobs.Items).To(gomega.BeEmpty())
114114

115115
ginkgo.By("Removing cronjob")
@@ -140,7 +140,7 @@ var _ = SIGDescribe("CronJob", func() {
140140

141141
ginkgo.By("Ensuring exactly one running job exists by listing jobs explicitly")
142142
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
143-
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
143+
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
144144
activeJobs, _ := filterActiveJobs(jobs)
145145
gomega.Expect(activeJobs).To(gomega.HaveLen(1))
146146

@@ -213,7 +213,7 @@ var _ = SIGDescribe("CronJob", func() {
213213

214214
ginkgo.By("Ensuring at least one running jobs exists by listing jobs explicitly")
215215
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
216-
framework.ExpectNoError(err, "Failed to list the CronJobs in namespace %s", f.Namespace.Name)
216+
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
217217
activeJobs, _ := filterActiveJobs(jobs)
218218
gomega.Expect(activeJobs).ToNot(gomega.BeEmpty())
219219

@@ -261,6 +261,31 @@ var _ = SIGDescribe("CronJob", func() {
261261
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
262262
})
263263

264+
ginkgo.It("should set the cronjob-scheduled-timestamp annotation on a job", func(ctx context.Context) {
265+
ginkgo.By("Creating a cronjob")
266+
cronJob := newTestCronJob("concurrent", "*/1 * * * ?", batchv1.AllowConcurrent,
267+
nil, nil, nil)
268+
cronJob, err := createCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob)
269+
framework.ExpectNoError(err, "Failed to create CronJob in namespace %s", f.Namespace.Name)
270+
271+
ginkgo.By("Ensuring CronJobsScheduledAnnotation annotation exists on the newely created job")
272+
err = waitForJobsAtLeast(ctx, f.ClientSet, f.Namespace.Name, 1)
273+
framework.ExpectNoError(err, "Failed to ensure a job exists in namespace %s", f.Namespace.Name)
274+
275+
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(ctx, metav1.ListOptions{})
276+
framework.ExpectNoError(err, "Failed to list jobs in namespace %s", f.Namespace.Name)
277+
gomega.Expect(jobs.Items[0].Annotations).Should(gomega.HaveKey(batchv1.CronJobScheduledTimestampAnnotation),
278+
"missing cronjob-scheduled-timestamp annotation")
279+
ginkgo.By("Ensuring CronJobsScheduledAnnotation annotation parses to RFC3339")
280+
timeAnnotation := jobs.Items[0].Annotations[batchv1.CronJobScheduledTimestampAnnotation]
281+
_, err = time.Parse(time.RFC3339, timeAnnotation)
282+
framework.ExpectNoError(err, "Failed to parse cronjob-scheduled-timestamp annotation: %q", timeAnnotation)
283+
284+
ginkgo.By("Removing cronjob")
285+
err = deleteCronJob(ctx, f.ClientSet, f.Namespace.Name, cronJob.Name)
286+
framework.ExpectNoError(err, "Failed to delete CronJob %s in namespace %s", cronJob.Name, f.Namespace.Name)
287+
})
288+
264289
// deleted jobs should be removed from the active list
265290
ginkgo.It("should remove from active list jobs that have been deleted", func(ctx context.Context) {
266291
ginkgo.By("Creating a ForbidConcurrent cronjob")

0 commit comments

Comments
 (0)