Skip to content

Commit

Permalink
fix(cli): Ensure --dry-run and --server-dry-run flags do not crea…
Browse files Browse the repository at this point in the history
…te workflows. fixes #12944 (#13183)

Signed-off-by: Miltiadis Alexis <alexmiltiadis@gmail.com>
Co-authored-by: Alan Clucas <alan@clucas.org>
(cherry picked from commit c59ff53)
  • Loading branch information
miltalex authored and agilgur5 committed Jul 11, 2024
1 parent 123a316 commit b79881c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,23 @@ func (s *workflowServer) SubmitWorkflow(ctx context.Context, req *workflowpkg.Wo
if err != nil {
return nil, sutils.ToStatusError(err, codes.InvalidArgument)
}

// if we are doing a normal dryRun, just return the workflow un-altered
if req.SubmitOptions != nil && req.SubmitOptions.DryRun {
return wf, nil
}
if req.SubmitOptions != nil && req.SubmitOptions.ServerDryRun {
// For a server dry run we require a namespace
if wf.Namespace == "" {
wf.Namespace = req.Namespace
}
workflow, err := util.CreateServerDryRun(ctx, wf, wfClient)
if err != nil {
return nil, sutils.ToStatusError(err, codes.InvalidArgument)
}
return workflow, nil
}

wf, err = wfClient.ArgoprojV1alpha1().Workflows(req.Namespace).Create(ctx, wf, metav1.CreateOptions{})
if err != nil {
return nil, sutils.ToStatusError(err, codes.InvalidArgument)
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/test/e2e/fixtures"
"github.com/argoproj/argo-workflows/v3/workflow/common"
)

const (
Expand Down Expand Up @@ -224,6 +225,42 @@ func (s *CLISuite) TestSubmitServerDryRun() {
})
}

func (s *CLISuite) TestSubmitWorkflowTemplateDryRun() {
s.Given().
WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml").
When().
CreateWorkflowTemplates().
RunCli([]string{"submit", "--dry-run", "--from", "workflowtemplate/workflow-template-whalesay-template", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Contains(t, output, "generateName: workflow-template-whalesay-template-")
// dry-run should never get a UID
assert.NotContains(t, output, "uid:")
}
}).
Then().
ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) {
assert.Equal(t, 0, len(wfList.Items))
})
}

func (s *CLISuite) TestSubmitWorkflowTemplateServerDryRun() {
s.Given().
WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml").
When().
CreateWorkflowTemplates().
RunCli([]string{"submit", "--server-dry-run", "--from", "workflowtemplate/workflow-template-whalesay-template", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Contains(t, output, "generateName: workflow-template-whalesay-template-")
// server-dry-run should get a UID
assert.Contains(t, output, "uid:")
}
}).
Then().
ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) {
assert.Equal(t, 0, len(wfList.Items))
})
}

func (s *CLISuite) TestTokenArg() {
if os.Getenv("CI") != "true" {
s.T().Skip("we only set-up the KUBECONFIG on CI")
Expand Down

0 comments on commit b79881c

Please sign in to comment.