Skip to content

Commit dd8630b

Browse files
authored
DisruptionCrons should not halt if they've missed 100 starts (#904)
* DisruptionCrons should be willing to retry scheduling indefinitely * DisruptionCrons should send TooLate metric when theyve missed a cron interval * Add a warning when DisruptionCrons find their last scheduled time in the future
1 parent 0a5f9d4 commit dd8630b

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

controllers/disruption_cron_controller.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ func (r *DisruptionCronReconciler) handleTargetResourceNowPresent(ctx context.Co
274274
// getNextSchedule calculates the next scheduled time for a DisruptionCron instance based on its cron schedule and the current time.
275275
// It returns the last missed schedule time, the next scheduled time, and any error encountered during parsing the schedule.
276276
func (r *DisruptionCronReconciler) getNextSchedule(instance *chaosv1beta1.DisruptionCron, now time.Time) (lastMissed time.Time, next time.Time, err error) {
277-
starts := 0
278277
sched, err := cron.ParseStandard(instance.Spec.Schedule)
279278

280279
if err != nil {
@@ -289,27 +288,14 @@ func (r *DisruptionCronReconciler) getNextSchedule(instance *chaosv1beta1.Disrup
289288
earliestTime = instance.ObjectMeta.CreationTimestamp.Time
290289
}
291290

292-
if instance.Spec.DelayedStartTolerance.Duration() > 0 {
293-
// controller is not going to schedule anything below this point
294-
schedulingDeadline := now.Add(-instance.Spec.DelayedStartTolerance.Duration())
295-
296-
if schedulingDeadline.After(earliestTime) {
297-
earliestTime = schedulingDeadline
298-
}
299-
}
300-
301291
if earliestTime.After(now) {
292+
r.log.Warnw("getNextSchedule has found itself in the past", "earliestTime", earliestTime.GoString(), "now", now.GoString())
293+
302294
return time.Time{}, sched.Next(now), nil
303295
}
304296

305297
for t := sched.Next(earliestTime); !t.After(now); t = sched.Next(t) {
306298
lastMissed = t
307-
starts++
308-
309-
if starts > 100 {
310-
// We can't get the most recent times so just return an empty slice
311-
return time.Time{}, time.Time{}, fmt.Errorf("too many missed start times (> 100)")
312-
}
313299
}
314300
r.handleMetricSinkError(r.MetricsSink.MetricNextScheduledTime(time.Until(sched.Next(now)), DisruptionCronTags))
315301

0 commit comments

Comments
 (0)