diff --git a/pkg/apis/workflow/v1alpha1/cron_workflow_types.go b/pkg/apis/workflow/v1alpha1/cron_workflow_types.go index 37a1f3203d07..dc74910bca5d 100644 --- a/pkg/apis/workflow/v1alpha1/cron_workflow_types.go +++ b/pkg/apis/workflow/v1alpha1/cron_workflow_types.go @@ -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 diff --git a/pkg/apis/workflow/v1alpha1/cron_workflow_types_test.go b/pkg/apis/workflow/v1alpha1/cron_workflow_types_test.go index ac13e45f80c5..d1af993c2086 100644 --- a/pkg/apis/workflow/v1alpha1/cron_workflow_types_test.go +++ b/pkg/apis/workflow/v1alpha1/cron_workflow_types_test.go @@ -16,16 +16,21 @@ 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 * * * *"}, @@ -33,5 +38,7 @@ func TestCronWorkflowSpec_GetScheduleString(t *testing.T) { 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()) } diff --git a/test/e2e/cron_test.go b/test/e2e/cron_test.go index d73bb65a6612..d212d76a88e7 100644 --- a/test/e2e/cron_test.go +++ b/test/e2e/cron_test.go @@ -219,7 +219,7 @@ kind: CronWorkflow metadata: name: test-cron-wf-basic-allow labels: - + spec: schedule: "* * * * *" concurrencyPolicy: "Allow" @@ -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) {