Skip to content

Commit

Permalink
fix(cron): schedules with timezone (#13363)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Clucas <[email protected]>
  • Loading branch information
Joibel authored Jul 20, 2024
1 parent 14038a3 commit 52cca7e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/workflow/v1alpha1/cron_workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (c *CronWorkflowSpec) getSchedules(withTimezone bool) []string {
if withTimezone {
schedule = c.withTimezone(schedule)
}
schedules[i] = c.withTimezone(schedule)
schedules[i] = schedule
}
}
return schedules
Expand Down
9 changes: 8 additions & 1 deletion pkg/apis/workflow/v1alpha1/cron_workflow_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@ func TestCronWorkflowStatus_HasActiveUID(t *testing.T) {
assert.False(t, cwfStatus.HasActiveUID("foo"))
}

func TestCronWorkflowSpec_GetScheduleString(t *testing.T) {
func TestCronWorkflowSpec_GetScheduleStrings(t *testing.T) {
cwfSpec := CronWorkflowSpec{
Timezone: "",
Schedule: "* * * * *",
}

assert.Equal(t, []string{"* * * * *"}, cwfSpec.GetSchedules())
assert.Equal(t, []string{"* * * * *"}, cwfSpec.GetSchedulesWithTimezone())
assert.Equal(t, "* * * * *", cwfSpec.GetScheduleString())

cwfSpec.Timezone = "America/Los_Angeles"
assert.Equal(t, []string{"* * * * *"}, cwfSpec.GetSchedules())
assert.Equal(t, []string{"CRON_TZ=America/Los_Angeles * * * * *"}, cwfSpec.GetSchedulesWithTimezone())
assert.Equal(t, "CRON_TZ=America/Los_Angeles * * * * *", cwfSpec.GetScheduleString())

cwfSpec = CronWorkflowSpec{
Timezone: "",
Schedules: []string{"* * * * *", "0 * * * *"},
}
assert.Equal(t, "* * * * *,0 * * * *", cwfSpec.GetScheduleString())

cwfSpec.Timezone = "America/Los_Angeles"
assert.Equal(t, []string{"* * * * *", "0 * * * *"}, cwfSpec.GetSchedules())
assert.Equal(t, []string{"CRON_TZ=America/Los_Angeles * * * * *", "CRON_TZ=America/Los_Angeles 0 * * * *"}, cwfSpec.GetSchedulesWithTimezone())
assert.Equal(t, "CRON_TZ=America/Los_Angeles * * * * *,CRON_TZ=America/Los_Angeles 0 * * * *", cwfSpec.GetScheduleString())
}
38 changes: 37 additions & 1 deletion test/e2e/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ kind: CronWorkflow
metadata:
name: test-cron-wf-basic-allow
labels:
spec:
schedule: "* * * * *"
concurrencyPolicy: "Allow"
Expand Down Expand Up @@ -426,6 +426,42 @@ spec:
assert.Equal(t, "true", cronWf.Labels[common.LabelKeyCronWorkflowCompleted])
})
})
s.Run("TestMultipleWithTimezone", func() {
s.T().Parallel()
s.Given().
CronWorkflow(`apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: test-multiple-with-timezone
spec:
schedules:
- "* * * * *"
- "0 1 * * *"
timezone: "America/Los_Angeles"
concurrencyPolicy: "Allow"
startingDeadlineSeconds: 0
successfulJobsHistoryLimit: 4
failedJobsHistoryLimit: 2
workflowSpec:
metadata:
labels:
workflows.argoproj.io/test: "true"
podGC:
strategy: OnPodCompletion
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2`).
When().
CreateCronWorkflow().
Wait(1 * time.Minute).
Then().
ExpectCron(func(t *testing.T, cronWf *wfv1.CronWorkflow) {
assert.Equal(t, cronWf.Spec.GetScheduleString(), cronWf.GetLatestSchedule())
assert.True(t, cronWf.Status.LastScheduledTime.Time.After(time.Now().Add(-1*time.Minute)))
})
})
}

func wfInformerListOptionsFunc(options *v1.ListOptions, cronWfName string) {
Expand Down

0 comments on commit 52cca7e

Please sign in to comment.