From 6e58b35c34c70df11d7727519249fff46a23ab2b Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Mon, 19 Jul 2021 11:04:02 -0400 Subject: [PATCH] fix(cli): Overridding name/generateName when creating CronWorkflows if specified (#6308) Signed-off-by: Yuan Tang --- cmd/argo/commands/cron/create.go | 11 +++++++++++ test/e2e/cli_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cmd/argo/commands/cron/create.go b/cmd/argo/commands/cron/create.go index 3488dd832cca..67ed419a5833 100644 --- a/cmd/argo/commands/cron/create.go +++ b/cmd/argo/commands/cron/create.go @@ -81,6 +81,17 @@ func CreateCronWorkflows(filePaths []string, cliOpts *cliCreateOpts, submitOpts log.Fatal(err) } cronWf.Spec.WorkflowSpec = newWf.Spec + // We have only copied the workflow spec to the cron workflow but not the metadata + // that includes name and generateName. Here we copy the metadata to the cron + // workflow's metadata and remove the unnecessary and mutually exclusive part. + if generateName := newWf.ObjectMeta.GenerateName; generateName != "" { + cronWf.ObjectMeta.GenerateName = generateName + cronWf.ObjectMeta.Name = "" + } + if name := newWf.ObjectMeta.Name; name != "" { + cronWf.ObjectMeta.Name = name + cronWf.ObjectMeta.GenerateName = "" + } if cronWf.Namespace == "" { cronWf.Namespace = client.Namespace() } diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go index 5709d5f0baa2..e8310ae0996e 100644 --- a/test/e2e/cli_test.go +++ b/test/e2e/cli_test.go @@ -1165,6 +1165,22 @@ func (s *CLISuite) TestCron() { }) }) + s.Run("Create Name Override", func() { + s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml", "--name", "basic-cron-wf-overridden-name", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { + if assert.NoError(t, err) { + assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-name") + } + }) + }) + + s.Run("Create GenerateName Override", func() { + s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml", "--generate-name", "basic-cron-wf-overridden-generate-name-", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { + if assert.NoError(t, err) { + assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-generate-name-") + } + }) + }) + s.Run("List", func() { s.Given().RunCli([]string{"cron", "list"}, func(t *testing.T, output string, err error) { if assert.NoError(t, err) {