From 0163b0a3c64194761c2aa603c3054e5850ffbc53 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Wed, 14 Sep 2016 16:06:21 +0200 Subject: [PATCH] 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. --- pkg/apis/batch/validation/validation.go | 7 +------ pkg/controller/scheduledjob/utils.go | 15 ++------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/pkg/apis/batch/validation/validation.go b/pkg/apis/batch/validation/validation.go index 24d97a53134..b840f892ae5 100644 --- a/pkg/apis/batch/validation/validation.go +++ b/pkg/apis/batch/validation/validation.go @@ -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())) } diff --git a/pkg/controller/scheduledjob/utils.go b/pkg/controller/scheduledjob/utils.go index 72e10b58a96..185624b38fe 100644 --- a/pkg/controller/scheduledjob/utils.go +++ b/pkg/controller/scheduledjob/utils.go @@ -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