From 5acb471755804b314b763a48cbf494e6137b4295 Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Thu, 8 Jul 2021 10:32:13 -0400 Subject: [PATCH 1/2] fix(cli): Overridding name/generateName when creating CronWorkflows if specified Signed-off-by: Yuan Tang --- cmd/argo/commands/cron/create.go | 8 ++++++++ test/e2e/cli_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/argo/commands/cron/create.go b/cmd/argo/commands/cron/create.go index 3488dd832cca..876d0c3afae8 100644 --- a/cmd/argo/commands/cron/create.go +++ b/cmd/argo/commands/cron/create.go @@ -81,6 +81,14 @@ func CreateCronWorkflows(filePaths []string, cliOpts *cliCreateOpts, submitOpts log.Fatal(err) } cronWf.Spec.WorkflowSpec = newWf.Spec + 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) { From 95cdcb3e814843d5232a29e6bbdc05bd714ef11a Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Wed, 14 Jul 2021 15:04:55 -0400 Subject: [PATCH 2/2] Add comment Signed-off-by: Yuan Tang --- cmd/argo/commands/cron/create.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/argo/commands/cron/create.go b/cmd/argo/commands/cron/create.go index 876d0c3afae8..67ed419a5833 100644 --- a/cmd/argo/commands/cron/create.go +++ b/cmd/argo/commands/cron/create.go @@ -81,6 +81,9 @@ 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 = ""