@@ -30,11 +30,11 @@ type CronDurationJob struct {
3030 key * quartz.JobKey
3131}
3232
33- // NewCronDurationJob constructs a new CronDurationJob.
33+ // newCronDurationJob constructs a new CronDurationJob.
3434// It also verifies the validity and correctness of the schedule and duration data.
3535// Internally, it assigns Location = Local if no location was specified in the schedule,
3636// and from that point onward, any time-related calculations are performed using this location.
37- func NewCronDurationJob (ctx context.Context , schedule * fleet.Schedule , scheduler quartz.Scheduler , c client.Client ) (* CronDurationJob , error ) {
37+ func newCronDurationJob (ctx context.Context , schedule * fleet.Schedule , scheduler quartz.Scheduler , c client.Client ) (* CronDurationJob , error ) {
3838 locationStr := schedule .Spec .Location
3939 if locationStr == "" {
4040 locationStr = "Local"
@@ -107,7 +107,7 @@ func getScheduleJobHash(sched *fleet.Schedule) (string, error) {
107107 return hex .EncodeToString (hash [:]), nil
108108}
109109
110- func (c * CronDurationJob ) calculateNextTimeBasedOnCron () (time.Duration , error ) {
110+ func (c * CronDurationJob ) durationToNextStart () (time.Duration , error ) {
111111 cronTrigger , err := quartz .NewCronTriggerWithLoc (c .Schedule .Spec .Schedule , c .Location )
112112 if err != nil {
113113 return 0 , err
@@ -172,7 +172,7 @@ func (c *CronDurationJob) updateJob(ctx context.Context) error {
172172}
173173
174174func (c * CronDurationJob ) rescheduleJob (ctx context.Context ) error {
175- next , err := c .calculateNextTimeBasedOnCron ()
175+ next , err := c .durationToNextStart ()
176176 if err != nil {
177177 return err
178178 }
@@ -231,6 +231,12 @@ func (c *CronDurationJob) executeStart(ctx context.Context) error {
231231 }
232232 }
233233
234+ // Sets Scheduled to true to all the matching clusters
235+ if err := setClustersScheduled (ctx , c .client , clusters , c .Schedule .Namespace , true ); err != nil {
236+ return err
237+ }
238+ c .MatchingClusters = clusters
239+
234240 // Update the status of the Schedule resource
235241 if err := setScheduleActive (ctx , c .client , c .Schedule , true ); err != nil {
236242 return err
@@ -243,7 +249,7 @@ func (c *CronDurationJob) executeStart(ctx context.Context) error {
243249func (c * CronDurationJob ) executeStop (ctx context.Context ) error {
244250 c .Started = false
245251
246- // Sets ActiveSchedule to true for all matching clusters.
252+ // Sets ActiveSchedule to false for all matching clusters.
247253 // This action disables the creation of BundleDeployments on the clusters.
248254 for _ , cluster := range c .MatchingClusters {
249255 if err := setClusterActiveSchedule (context .Background (), c .client , cluster , c .Schedule .Namespace , false ); err != nil {
@@ -271,7 +277,7 @@ func matchingClusters(ctx context.Context, matcher *matcher.ScheduleMatch, c cli
271277 cluster := cluster
272278 cgs , err := target .ClusterGroupsForCluster (ctx , c , & cluster )
273279 if err != nil {
274- return nil , fmt .Errorf ("%w, getting clusters from cluster groups: %w" , fleetutil .ErrRetryable , err )
280+ return nil , fmt .Errorf ("%w, getting cluster groups from clusters : %w" , fleetutil .ErrRetryable , err )
275281 }
276282
277283 if matcher .MatchCluster (cluster .Name , target .ClusterGroupsToLabelMap (cgs ), cluster .Labels ) {
0 commit comments