Skip to content

Commit

Permalink
fix(cli): Overridding name/generateName when creating CronWorkflows i…
Browse files Browse the repository at this point in the history
…f specified (argoproj#6308)

Signed-off-by: Yuan Tang <[email protected]>
  • Loading branch information
terrytangyuan committed Jul 19, 2021
1 parent 5f0d6ab commit 6e58b35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/argo/commands/cron/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6e58b35

Please sign in to comment.