From 4050b08f03d25da333ae30d1e23aa95b1947fcd6 Mon Sep 17 00:00:00 2001 From: Iven Hsu Date: Tue, 12 Oct 2021 15:48:43 +0800 Subject: [PATCH] fix: Skip empty withParam tasks. Fixes #6834 Signed-off-by: Iven Hsu --- test/e2e/functional/dag-empty-param.yaml | 39 ++++++++++++++++++++++++ test/e2e/functional_test.go | 17 +++++++++++ workflow/controller/dag.go | 7 ++++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/e2e/functional/dag-empty-param.yaml diff --git a/test/e2e/functional/dag-empty-param.yaml b/test/e2e/functional/dag-empty-param.yaml new file mode 100644 index 000000000000..6593c4af9ff4 --- /dev/null +++ b/test/e2e/functional/dag-empty-param.yaml @@ -0,0 +1,39 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + generateName: dag-param-result- +spec: + entrypoint: dag-param-result-example + templates: + - name: dag-param-result-example + dag: + tasks: + - name: generate + template: gen-number-list + - name: sleep + template: sleep-n-sec + arguments: + parameters: + - name: seconds + value: "{{item}}" + withParam: "{{tasks.generate.outputs.result}}" + dependencies: + - generate + + - name: gen-number-list + script: + image: python:alpine3.6 + command: [python] + source: | + import json + import sys + json.dump([i for i in range(0, -1)], sys.stdout) + + - name: sleep-n-sec + inputs: + parameters: + - name: seconds + container: + image: argoproj/argosay:v1 + command: [sh, -c] + args: ["echo sleeping for {{inputs.parameters.seconds}} seconds; sleep {{inputs.parameters.seconds}}; echo done"] diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index f68d102e9c54..843aab21a525 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -401,6 +401,23 @@ func (s *FunctionalSuite) TestLoopEmptyParam() { }) } +func (s *FunctionalSuite) TestDAGEmptyParam() { + s.Given(). + Workflow("@functional/dag-empty-param.yaml"). + When(). + SubmitWorkflow(). + WaitForWorkflow(). + Then(). + ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase) + if assert.Len(t, status.Nodes, 3) { + nodeStatus := status.Nodes.FindByDisplayName("sleep") + assert.Equal(t, wfv1.NodeSkipped, nodeStatus.Phase) + assert.Equal(t, "Skipped, empty params", nodeStatus.Message) + } + }) +} + // 128M is for argo executor func (s *FunctionalSuite) TestPendingRetryWorkflow() { s.Given(). diff --git a/workflow/controller/dag.go b/workflow/controller/dag.go index 55cdb21b6b30..7304a48f4797 100644 --- a/workflow/controller/dag.go +++ b/workflow/controller/dag.go @@ -437,7 +437,12 @@ func (woc *wfOperationCtx) executeDAGTask(ctx context.Context, dagCtx *dagContex // For example, if we had task A with withItems of ['foo', 'bar'] which expanded to ['A(0:foo)', 'A(1:bar)'], we still // need to create a node for A. if task.ShouldExpand() { - if taskGroupNode == nil { + // DAG task with empty withParams list should be skipped + if len(expandedTasks) == 0 { + skipReason := "Skipped, empty params" + woc.initializeNode(nodeName, wfv1.NodeTypeSkipped, dagTemplateScope, task, dagCtx.boundaryID, wfv1.NodeSkipped, skipReason) + connectDependencies(nodeName) + } else if taskGroupNode == nil { connectDependencies(nodeName) taskGroupNode = woc.initializeNode(nodeName, wfv1.NodeTypeTaskGroup, dagTemplateScope, task, dagCtx.boundaryID, wfv1.NodeRunning, "") }