@@ -271,7 +271,7 @@ var _ = Describe("ScheduleReconciler", func() {
271271 ObjectMeta : metav1.ObjectMeta {
272272 Name : "test-cluster2" ,
273273 Namespace : "default" ,
274- Labels : map [string ]string {"env" : "test" },
274+ Labels : map [string ]string {"env" : "test" , "foo" : "bar" },
275275 },
276276 }
277277
@@ -305,10 +305,28 @@ var _ = Describe("ScheduleReconciler", func() {
305305
306306 // clusters 1, 2 and 3 should be scheduled in the quartz.Scheduler and also
307307 // be flagged as Scheduled
308- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , true , true )
309- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster2" , "default" , true , true )
310- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster3" , "default" , true , true )
311- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster4" , "default" , false , false )
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 )
312+
313+ // force the start of the schedule (so it sets .Status.ActiveSchedule=true)
314+ jobKey := scheduleKey (schedule )
315+ job , err := scheduler .GetScheduledJob (jobKey )
316+ Expect (err ).NotTo (HaveOccurred ())
317+
318+ cronDurationJob , ok := job .JobDetail ().Job ().(* CronDurationJob )
319+ Expect (ok ).To (BeTrue ())
320+
321+ // Manually trigger start
322+ err = cronDurationJob .executeStart (ctx )
323+ Expect (err ).NotTo (HaveOccurred ())
324+
325+ // 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 )
312330
313331 // update the schedule, now it only looks for the label foo=bar
314332 scheduleUpdated := & fleet.Schedule {}
@@ -326,11 +344,13 @@ var _ = Describe("ScheduleReconciler", func() {
326344 _ , err = reconciler .Reconcile (ctx , req )
327345 Expect (err ).NotTo (HaveOccurred ())
328346
329- // now only 1 cluster should be flagged as scheduled and be in the scheduled jobs list
330- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , false , false )
331- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster2" , "default" , false , false )
332- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster3" , "default" , false , false )
333- checkClusterIsScheduled (scheduler , k8sclient , "test-cluster4" , "default" , true , true )
347+ // cluster 2 and 4 should be still targetted.
348+ checkClusterIsScheduled (scheduler , k8sclient , "test-cluster" , "default" , false , false , false )
349+ // cluster 2 had Status.ActiveSchedule set to true, but because we updated the Schedule
350+ // 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 )
334354 })
335355 })
336356})
@@ -339,7 +359,7 @@ func checkClusterIsScheduled(
339359 scheduler quartz.Scheduler ,
340360 k8sclient client.Client ,
341361 cluster , namespace string ,
342- scheduledExpected , flaggedAsScheduledExpected bool ) {
362+ scheduledExpected , flaggedAsScheduledExpected , activeScheduleExpected bool ) {
343363 isScheduled , err := isClusterScheduled (scheduler , cluster , namespace )
344364 Expect (err ).NotTo (HaveOccurred ())
345365 Expect (isScheduled ).To (Equal (scheduledExpected ))
@@ -349,4 +369,5 @@ func checkClusterIsScheduled(
349369 err = k8sclient .Get (context .Background (), key , clusterObj )
350370 Expect (err ).NotTo (HaveOccurred ())
351371 Expect (clusterObj .Status .Scheduled ).To (Equal (flaggedAsScheduledExpected ))
372+ Expect (clusterObj .Status .ActiveSchedule ).To (Equal (activeScheduleExpected ))
352373}
0 commit comments