mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Merge pull request #30227 from soltysh/remove_seconds
Automatic merge from submit-queue Remove seconds from scheduled jobs cron format @erictune @janetkuo as promised this removes the seconds from the cron format <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/30227) <!-- Reviewable:end -->
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
// schedule is hourly on the hour
|
||||
var (
|
||||
onTheHour string = "0 0 * * * ?"
|
||||
onTheHour string = "0 * * * ?"
|
||||
)
|
||||
|
||||
func justBeforeTheHour() time.Time {
|
||||
@@ -83,7 +83,7 @@ func scheduledJob() batch.ScheduledJob {
|
||||
CreationTimestamp: unversioned.Time{Time: justBeforeTheHour()},
|
||||
},
|
||||
Spec: batch.ScheduledJobSpec{
|
||||
Schedule: "0 0 * * * * ?",
|
||||
Schedule: "* * * * ?",
|
||||
ConcurrencyPolicy: batch.AllowConcurrent,
|
||||
JobTemplate: batch.JobTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
||||
@@ -111,8 +111,8 @@ 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?
|
||||
|
||||
sched, err := cron.Parse(schedule)
|
||||
tmpSched := addSeconds(schedule)
|
||||
sched, err := cron.Parse(tmpSched)
|
||||
if err != nil {
|
||||
return time.Unix(0, 0), fmt.Errorf("Unparseable schedule: %s : %s", schedule, err)
|
||||
}
|
||||
@@ -125,7 +125,8 @@ 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{}
|
||||
sched, err := cron.Parse(sj.Spec.Schedule)
|
||||
tmpSched := addSeconds(sj.Spec.Schedule)
|
||||
sched, err := cron.Parse(tmpSched)
|
||||
if err != nil {
|
||||
return starts, fmt.Errorf("Unparseable schedule: %s : %s", sj.Spec.Schedule, err)
|
||||
}
|
||||
@@ -173,6 +174,15 @@ 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
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestGetJobFromTemplate(t *testing.T) {
|
||||
SelfLink: "/apis/extensions/v1beta1/namespaces/snazzycats/jobs/myscheduledjob",
|
||||
},
|
||||
Spec: batch.ScheduledJobSpec{
|
||||
Schedule: "0 0 * * * * ?",
|
||||
Schedule: "* * * * ?",
|
||||
ConcurrencyPolicy: batch.AllowConcurrent,
|
||||
JobTemplate: batch.JobTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
@@ -256,7 +256,7 @@ func TestGroupJobsByParent(t *testing.T) {
|
||||
|
||||
func TestGetRecentUnmetScheduleTimes(t *testing.T) {
|
||||
// schedule is hourly on the hour
|
||||
schedule := "0 0 * * * ?"
|
||||
schedule := "0 * * * ?"
|
||||
// T1 is a scheduled start time of that schedule
|
||||
T1, err := time.Parse(time.RFC3339, "2016-05-19T10:00:00Z")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user