Skip to content

Commit c59ff53

Browse files
miltalexJoibel
andauthored
fix(cli): Ensure --dry-run and --server-dry-run flags do not create workflows. fixes argoproj#12944 (argoproj#13183)
Signed-off-by: Miltiadis Alexis <alexmiltiadis@gmail.com> Co-authored-by: Alan Clucas <alan@clucas.org>
1 parent fc0f34e commit c59ff53

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

server/workflow/workflow_server.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,23 @@ func (s *workflowServer) SubmitWorkflow(ctx context.Context, req *workflowpkg.Wo
780780
if err != nil {
781781
return nil, sutils.ToStatusError(err, codes.InvalidArgument)
782782
}
783+
784+
// if we are doing a normal dryRun, just return the workflow un-altered
785+
if req.SubmitOptions != nil && req.SubmitOptions.DryRun {
786+
return wf, nil
787+
}
788+
if req.SubmitOptions != nil && req.SubmitOptions.ServerDryRun {
789+
// For a server dry run we require a namespace
790+
if wf.Namespace == "" {
791+
wf.Namespace = req.Namespace
792+
}
793+
workflow, err := util.CreateServerDryRun(ctx, wf, wfClient)
794+
if err != nil {
795+
return nil, sutils.ToStatusError(err, codes.InvalidArgument)
796+
}
797+
return workflow, nil
798+
}
799+
783800
wf, err = wfClient.ArgoprojV1alpha1().Workflows(req.Namespace).Create(ctx, wf, metav1.CreateOptions{})
784801
if err != nil {
785802
return nil, sutils.ToStatusError(err, codes.InvalidArgument)

test/e2e/cli_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
2323
"github.com/argoproj/argo-workflows/v3/test/e2e/fixtures"
24+
"github.com/argoproj/argo-workflows/v3/workflow/common"
2425
)
2526

2627
const (
@@ -224,6 +225,42 @@ func (s *CLISuite) TestSubmitServerDryRun() {
224225
})
225226
}
226227

228+
func (s *CLISuite) TestSubmitWorkflowTemplateDryRun() {
229+
s.Given().
230+
WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml").
231+
When().
232+
CreateWorkflowTemplates().
233+
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) {
234+
if assert.NoError(t, err) {
235+
assert.Contains(t, output, "generateName: workflow-template-whalesay-template-")
236+
// dry-run should never get a UID
237+
assert.NotContains(t, output, "uid:")
238+
}
239+
}).
240+
Then().
241+
ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) {
242+
assert.Equal(t, 0, len(wfList.Items))
243+
})
244+
}
245+
246+
func (s *CLISuite) TestSubmitWorkflowTemplateServerDryRun() {
247+
s.Given().
248+
WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml").
249+
When().
250+
CreateWorkflowTemplates().
251+
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) {
252+
if assert.NoError(t, err) {
253+
assert.Contains(t, output, "generateName: workflow-template-whalesay-template-")
254+
// server-dry-run should get a UID
255+
assert.Contains(t, output, "uid:")
256+
}
257+
}).
258+
Then().
259+
ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) {
260+
assert.Equal(t, 0, len(wfList.Items))
261+
})
262+
}
263+
227264
func (s *CLISuite) TestTokenArg() {
228265
if os.Getenv("CI") != "true" {
229266
s.T().Skip("we only set-up the KUBECONFIG on CI")

0 commit comments

Comments
 (0)