@@ -229,72 +229,71 @@ var _ = SIGDescribe("CronJob", func() {
229
229
framework .ExpectNoError (err , "Failed to remove %s cronjob in namespace %s" , cronJob .Name , f .Namespace .Name )
230
230
})
231
231
232
- // cleanup of successful/failed finished jobs, with successfulJobsHistoryLimit and failedJobsHistoryLimit
233
- ginkgo .It ("should delete successful/failed finished jobs with limit of one job [Flaky]" , func () {
234
-
235
- testCases := []struct {
236
- description string
237
- command []string
238
- successLimit int32
239
- failedLimit int32
240
- }{
241
- {
242
- description : "successful-jobs-history-limit" ,
243
- command : successCommand ,
244
- successLimit : 1 , // keep one successful job
245
- failedLimit : 0 , // keep none failed job
246
- },
247
- {
248
- description : "failed-jobs-history-limit" ,
249
- command : failureCommand ,
250
- successLimit : 0 , // keep none succcessful job
251
- failedLimit : 1 , // keep one failed job
252
- },
253
- }
232
+ // cleanup of successful finished jobs, with limit of one successful job
233
+ ginkgo .It ("should delete successful finished jobs with limit of one successful job" , func () {
234
+ ginkgo .By ("Creating an AllowConcurrent cronjob with custom history limit" )
235
+ successLimit := int32 (1 )
236
+ failedLimit := int32 (0 )
237
+ cronJob := newTestCronJob ("successful-jobs-history-limit" , "*/1 * * * ?" , batchv1beta1 .AllowConcurrent ,
238
+ successCommand , & successLimit , & failedLimit )
239
+
240
+ ensureHistoryLimits (f .ClientSet , f .Namespace .Name , cronJob )
241
+ })
254
242
255
- for _ , t := range testCases {
256
- ginkgo .By (fmt .Sprintf ("Creating a AllowConcurrent cronjob with custom %s" , t .description ))
257
- cronJob := newTestCronJob (t .description , "*/1 * * * ?" , batchv1beta1 .AllowConcurrent ,
258
- t .command , & t .successLimit , & t .failedLimit )
259
- cronJob , err := createCronJob (f .ClientSet , f .Namespace .Name , cronJob )
260
- framework .ExpectNoError (err , "Failed to create allowconcurrent cronjob with custom history limits in namespace %s" , f .Namespace .Name )
261
-
262
- // Job is going to complete instantly: do not check for an active job
263
- // as we are most likely to miss it
264
-
265
- ginkgo .By ("Ensuring a finished job exists" )
266
- err = waitForAnyFinishedJob (f .ClientSet , f .Namespace .Name )
267
- framework .ExpectNoError (err , "Failed to ensure a finished cronjob exists in namespace %s" , f .Namespace .Name )
268
-
269
- ginkgo .By ("Ensuring a finished job exists by listing jobs explicitly" )
270
- jobs , err := f .ClientSet .BatchV1 ().Jobs (f .Namespace .Name ).List (metav1.ListOptions {})
271
- framework .ExpectNoError (err , "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s" , f .Namespace .Name )
272
- activeJobs , finishedJobs := filterActiveJobs (jobs )
273
- if len (finishedJobs ) != 1 {
274
- framework .Logf ("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v" , f .Namespace .Name , activeJobs , finishedJobs )
275
- framework .ExpectEqual (len (finishedJobs ), 1 )
276
- }
243
+ // cleanup of failed finished jobs, with limit of one failed job
244
+ ginkgo .It ("should delete failed finished jobs with limit of one job" , func () {
245
+ ginkgo .By ("Creating an AllowConcurrent cronjob with custom history limit" )
246
+ successLimit := int32 (0 )
247
+ failedLimit := int32 (1 )
248
+ cronJob := newTestCronJob ("failed-jobs-history-limit" , "*/1 * * * ?" , batchv1beta1 .AllowConcurrent ,
249
+ failureCommand , & successLimit , & failedLimit )
277
250
278
- // Job should get deleted when the next job finishes the next minute
279
- ginkgo .By ("Ensuring this job and its pods does not exist anymore" )
280
- err = waitForJobToDisappear (f .ClientSet , f .Namespace .Name , finishedJobs [0 ])
281
- framework .ExpectNoError (err , "Failed to ensure that job does not exists anymore in namespace %s" , f .Namespace .Name )
282
- err = waitForJobsPodToDisappear (f .ClientSet , f .Namespace .Name , finishedJobs [0 ])
283
- framework .ExpectNoError (err , "Failed to ensure that pods for job does not exists anymore in namespace %s" , f .Namespace .Name )
284
-
285
- ginkgo .By ("Ensuring there is 1 finished job by listing jobs explicitly" )
286
- jobs , err = f .ClientSet .BatchV1 ().Jobs (f .Namespace .Name ).List (metav1.ListOptions {})
287
- framework .ExpectNoError (err , "Failed to ensure there is one finished job by listing job explicitly in namespace %s" , f .Namespace .Name )
288
- _ , finishedJobs = filterActiveJobs (jobs )
289
- framework .ExpectEqual (len (finishedJobs ), 1 )
290
-
291
- ginkgo .By ("Removing cronjob" )
292
- err = deleteCronJob (f .ClientSet , f .Namespace .Name , cronJob .Name )
293
- framework .ExpectNoError (err , "Failed to remove the %s cronjob in namespace %s" , cronJob .Name , f .Namespace .Name )
294
- }
251
+ ensureHistoryLimits (f .ClientSet , f .Namespace .Name , cronJob )
295
252
})
253
+
296
254
})
297
255
256
+ func ensureHistoryLimits (c clientset.Interface , ns string , cronJob * batchv1beta1.CronJob ) {
257
+ cronJob , err := createCronJob (c , ns , cronJob )
258
+ framework .ExpectNoError (err , "Failed to create allowconcurrent cronjob with custom history limits in namespace %s" , ns )
259
+
260
+ // Job is going to complete instantly: do not check for an active job
261
+ // as we are most likely to miss it
262
+
263
+ ginkgo .By ("Ensuring a finished job exists" )
264
+ err = waitForAnyFinishedJob (c , ns )
265
+ framework .ExpectNoError (err , "Failed to ensure a finished cronjob exists in namespace %s" , ns )
266
+
267
+ ginkgo .By ("Ensuring a finished job exists by listing jobs explicitly" )
268
+ jobs , err := c .BatchV1 ().Jobs (ns ).List (metav1.ListOptions {})
269
+ framework .ExpectNoError (err , "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s" , ns )
270
+ activeJobs , finishedJobs := filterActiveJobs (jobs )
271
+ if len (finishedJobs ) != 1 {
272
+ framework .Logf ("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v" , ns , activeJobs , finishedJobs )
273
+ framework .ExpectEqual (len (finishedJobs ), 1 )
274
+ }
275
+
276
+ // Job should get deleted when the next job finishes the next minute
277
+ ginkgo .By ("Ensuring this job and its pods does not exist anymore" )
278
+ err = waitForJobToDisappear (c , ns , finishedJobs [0 ])
279
+ framework .ExpectNoError (err , "Failed to ensure that job does not exists anymore in namespace %s" , ns )
280
+ err = waitForJobsPodToDisappear (c , ns , finishedJobs [0 ])
281
+ framework .ExpectNoError (err , "Failed to ensure that pods for job does not exists anymore in namespace %s" , ns )
282
+
283
+ ginkgo .By ("Ensuring there is 1 finished job by listing jobs explicitly" )
284
+ jobs , err = c .BatchV1 ().Jobs (ns ).List (metav1.ListOptions {})
285
+ framework .ExpectNoError (err , "Failed to ensure there is one finished job by listing job explicitly in namespace %s" , ns )
286
+ activeJobs , finishedJobs = filterActiveJobs (jobs )
287
+ if len (finishedJobs ) != 1 {
288
+ framework .Logf ("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v" , ns , activeJobs , finishedJobs )
289
+ framework .ExpectEqual (len (finishedJobs ), 1 )
290
+ }
291
+
292
+ ginkgo .By ("Removing cronjob" )
293
+ err = deleteCronJob (c , ns , cronJob .Name )
294
+ framework .ExpectNoError (err , "Failed to remove the %s cronjob in namespace %s" , cronJob .Name , ns )
295
+ }
296
+
298
297
// newTestCronJob returns a cronjob which does one of several testing behaviors.
299
298
func newTestCronJob (name , schedule string , concurrencyPolicy batchv1beta1.ConcurrencyPolicy ,
300
299
command []string , successfulJobsHistoryLimit * int32 , failedJobsHistoryLimit * int32 ) * batchv1beta1.CronJob {
0 commit comments