@@ -265,16 +265,19 @@ func setClusterScheduled(ctx context.Context, c client.Client, name, namespace s
265265 return fmt .Errorf ("%w, getting cluster: %w" , fleetutil .ErrRetryable , err )
266266 }
267267
268- // if the value is already the expected one , avoid the update
269- if cluster .Status .Scheduled == scheduled {
268+ // if the values are already the expected ones , avoid the update
269+ if cluster .Status .Scheduled == scheduled && ! cluster . Status . ActiveSchedule {
270270 return nil
271271 }
272272
273273 old := cluster .DeepCopy ()
274274 cluster .Status .Scheduled = scheduled
275- if ! scheduled {
276- cluster .Status .ActiveSchedule = false
277- }
275+
276+ // when this function is called is either because we're updating a
277+ // Schedule or because we're creating it.
278+ // In both cases ActiveSchedule should be false as a Schedule
279+ // always begins in OffSchedule mode until the first start call is executed.
280+ cluster .Status .ActiveSchedule = false
278281
279282 return updateClusterStatus (ctx , c , old , cluster )
280283}
@@ -413,10 +416,11 @@ func setClustersScheduled(ctx context.Context, c client.Client, clusters []strin
413416func updateScheduledClusters (ctx context.Context , scheduler quartz.Scheduler , c client.Client , clustersNew []string , clustersOld []string , namespace string ) error {
414417 // first look for clusters that are not scheduled yet and flag them as scheduled
415418 for _ , cluster := range clustersNew {
416- if ! slices .Contains (clustersOld , cluster ) {
417- if err := setClusterScheduled (ctx , c , cluster , namespace , true ); err != nil {
418- return err
419- }
419+ // set schedule to true and also reset the activeSchedule property
420+ // When we update a Schedule it begins from a offSchedule status until
421+ // executeStart is called.
422+ if err := setClusterScheduled (ctx , c , cluster , namespace , true ); err != nil {
423+ return err
420424 }
421425 }
422426
0 commit comments