@@ -19,6 +19,12 @@ import (
1919 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2020)
2121
22+ type expected struct {
23+ scheduledJob bool
24+ statusScheduled bool
25+ statusActiveSchedule bool
26+ }
27+
2228var _ = Describe ("ScheduleReconciler" , func () {
2329 var (
2430 ctx context.Context
@@ -305,10 +311,14 @@ var _ = Describe("ScheduleReconciler", func() {
305311
306312 // clusters 1, 2 and 3 should be scheduled in the quartz.Scheduler and also
307313 // be flagged as Scheduled
308- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , true , true , false )
309- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster2" , "default" , true , true , false )
310- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster3" , "default" , true , true , false )
311- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster4" , "default" , false , false , false )
314+ checkState (scheduler , k8sclient , "test-cluster" , "default" ,
315+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : false })
316+ checkState (scheduler , k8sclient , "test-cluster2" , "default" ,
317+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : false })
318+ checkState (scheduler , k8sclient , "test-cluster3" , "default" ,
319+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : false })
320+ checkState (scheduler , k8sclient , "test-cluster4" , "default" ,
321+ expected {scheduledJob : false , statusScheduled : false , statusActiveSchedule : false })
312322
313323 // force the start of the schedule (so it sets .Status.ActiveSchedule=true)
314324 jobKey := scheduleKey (schedule )
@@ -323,10 +333,14 @@ var _ = Describe("ScheduleReconciler", func() {
323333 Expect (err ).NotTo (HaveOccurred ())
324334
325335 // check now that the clusters have the expected values, specially Status.ActiveSchedule
326- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , true , true , true )
327- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster2" , "default" , true , true , true )
328- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster3" , "default" , true , true , true )
329- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster4" , "default" , false , false , false )
336+ checkState (scheduler , k8sclient , "test-cluster" , "default" ,
337+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : true })
338+ checkState (scheduler , k8sclient , "test-cluster2" , "default" ,
339+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : true })
340+ checkState (scheduler , k8sclient , "test-cluster3" , "default" ,
341+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : true })
342+ checkState (scheduler , k8sclient , "test-cluster4" , "default" ,
343+ expected {scheduledJob : false , statusScheduled : false , statusActiveSchedule : false })
330344
331345 // update the schedule, now it only looks for the label foo=bar
332346 scheduleUpdated := & fleet.Schedule {}
@@ -345,29 +359,33 @@ var _ = Describe("ScheduleReconciler", func() {
345359 Expect (err ).NotTo (HaveOccurred ())
346360
347361 // cluster 2 and 4 should be still targeted.
348- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , false , false , false )
362+ checkState (scheduler , k8sclient , "test-cluster" , "default" ,
363+ expected {scheduledJob : false , statusScheduled : false , statusActiveSchedule : false })
349364 // cluster 2 had Status.ActiveSchedule set to true, but because we updated the Schedule
350365 // it should be back to false.
351- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster2" , "default" , true , true , false )
352- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster3" , "default" , false , false , false )
353- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster4" , "default" , true , true , false )
366+ checkState (scheduler , k8sclient , "test-cluster2" , "default" ,
367+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : false })
368+ checkState (scheduler , k8sclient , "test-cluster3" , "default" ,
369+ expected {scheduledJob : false , statusScheduled : false , statusActiveSchedule : false })
370+ checkState (scheduler , k8sclient , "test-cluster4" , "default" ,
371+ expected {scheduledJob : true , statusScheduled : true , statusActiveSchedule : false })
354372 })
355373 })
356374})
357375
358- func checkClusterIsScheduled (
376+ func checkState (
359377 scheduler quartz.Scheduler ,
360378 k8sclient client.Client ,
361379 cluster , namespace string ,
362- scheduledExpected , flaggedAsScheduledExpected , activeScheduleExpected bool ) {
380+ expectedState expected ) {
363381 isScheduled , err := isClusterScheduled (scheduler , cluster , namespace )
364382 Expect (err ).NotTo (HaveOccurred ())
365- Expect (isScheduled ).To (Equal (scheduledExpected ))
383+ Expect (isScheduled ).To (Equal (expectedState . scheduledJob ))
366384
367385 key := client.ObjectKey {Name : cluster , Namespace : namespace }
368386 clusterObj := & fleet.Cluster {}
369387 err = k8sclient .Get (context .Background (), key , clusterObj )
370388 Expect (err ).NotTo (HaveOccurred ())
371- Expect (clusterObj .Status .Scheduled ).To (Equal (flaggedAsScheduledExpected ))
372- Expect (clusterObj .Status .ActiveSchedule ).To (Equal (activeScheduleExpected ))
389+ Expect (clusterObj .Status .Scheduled ).To (Equal (expectedState . statusScheduled ))
390+ Expect (clusterObj .Status .ActiveSchedule ).To (Equal (expectedState . statusActiveSchedule ))
373391}
0 commit comments