mirror of https://github.com/k3s-io/k3s
Remove hacks from ScheduledJobs cron spec parsing
Previusly github.com/robfig/cron library did not allow passing cron spec without seconds. Previous commit updates the library, which has additional method ParseStandard which follows the standard cron spec, iow. minute, hour, day of month, month, day of week.pull/6/head
parent
03555ab1ae
commit
0163b0a3c6
|
@ -199,12 +199,7 @@ func validateConcurrencyPolicy(concurrencyPolicy *batch.ConcurrencyPolicy, fldPa
|
|||
|
||||
func validateScheduleFormat(schedule string, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
// TODO soltysh: this should be removed when https://github.com/robfig/cron/issues/58 is fixed
|
||||
tmpSchedule := schedule
|
||||
if len(schedule) > 0 && schedule[0] != '@' {
|
||||
tmpSchedule = "0 " + schedule
|
||||
}
|
||||
if _, err := cron.Parse(tmpSchedule); err != nil {
|
||||
if _, err := cron.ParseStandard(schedule); err != nil {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath, schedule, err.Error()))
|
||||
}
|
||||
|
||||
|
|
|
@ -109,8 +109,7 @@ func getNextStartTimeAfter(schedule string, now time.Time) (time.Time, error) {
|
|||
// How to handle concurrency control.
|
||||
// How to detect changes to schedules or deleted schedules and then
|
||||
// update the jobs?
|
||||
tmpSched := addSeconds(schedule)
|
||||
sched, err := cron.Parse(tmpSched)
|
||||
sched, err := cron.Parse(schedule)
|
||||
if err != nil {
|
||||
return time.Unix(0, 0), fmt.Errorf("Unparseable schedule: %s : %s", schedule, err)
|
||||
}
|
||||
|
@ -123,8 +122,7 @@ func getNextStartTimeAfter(schedule string, now time.Time) (time.Time, error) {
|
|||
// If there were missed times prior to the last known start time, then those are not returned.
|
||||
func getRecentUnmetScheduleTimes(sj batch.ScheduledJob, now time.Time) ([]time.Time, error) {
|
||||
starts := []time.Time{}
|
||||
tmpSched := addSeconds(sj.Spec.Schedule)
|
||||
sched, err := cron.Parse(tmpSched)
|
||||
sched, err := cron.ParseStandard(sj.Spec.Schedule)
|
||||
if err != nil {
|
||||
return starts, fmt.Errorf("Unparseable schedule: %s : %s", sj.Spec.Schedule, err)
|
||||
}
|
||||
|
@ -172,15 +170,6 @@ func getRecentUnmetScheduleTimes(sj batch.ScheduledJob, now time.Time) ([]time.T
|
|||
return starts, nil
|
||||
}
|
||||
|
||||
// TODO soltysh: this should be removed when https://github.com/robfig/cron/issues/58 is fixed
|
||||
func addSeconds(schedule string) string {
|
||||
tmpSched := schedule
|
||||
if len(schedule) > 0 && schedule[0] != '@' {
|
||||
tmpSched = "0 " + schedule
|
||||
}
|
||||
return tmpSched
|
||||
}
|
||||
|
||||
// XXX unit test this
|
||||
|
||||
// getJobFromTemplate makes a Job from a ScheduledJob
|
||||
|
|
Loading…
Reference in New Issue