Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Overridding name/generateName when creating CronWorkflows if specified #6308

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems hacky, it your comment suggests there is a good reason. Maybe add a code comment here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added comment.

// 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