Skip to content

Commit 6208921

Browse files
isubasingheBartek Kowalczyk
andcommitted
fix: populate scope with empty values for outputs of skipped/omitted steps
Signed-off-by: Bartek Kowalczyk <kowalczyk.bartek.mail@gmail.com> Co-Authored-By: Bartek Kowalczyk <kowalczyk.bartek.mail@gmail.com> Signed-off-by: isubasinghe <isitha@pipekit.io>
1 parent d2df982 commit 6208921

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Workflow
3+
metadata:
4+
generateName: steps-skipped-output-ref-
5+
spec:
6+
entrypoint: main
7+
templates:
8+
- name: main
9+
steps:
10+
- - name: job1
11+
template: run-job
12+
- - name: job2
13+
template: run-job
14+
when: "\"{{steps.job1.outputs.parameters.status}}\" == \"FAILED\""
15+
- - name: job2-error-handler
16+
template: run-job
17+
when: "\"{{steps.job2.outputs.parameters.status}}\" != \"SUCCESS\" && \"{{steps.job1.outputs.parameters.status}}\" == \"SUCCESS\""
18+
- name: run-job
19+
outputs:
20+
parameters:
21+
- name: status
22+
valueFrom:
23+
path: /tmp/status.txt
24+
container:
25+
image: argoproj/argosay:v2
26+
args: ["echo", "SUCCESS", "/tmp/status.txt"]

test/e2e/functional_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,32 @@ func (s *FunctionalSuite) TestDAGSkippedOutputRef() {
512512
})
513513
}
514514

515+
func (s *FunctionalSuite) TestStepsSkippedOutputRef() {
516+
s.Given().
517+
Workflow("@functional/steps-skipped-output-ref.yaml").
518+
When().
519+
SubmitWorkflow().
520+
WaitForWorkflow().
521+
Then().
522+
ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
523+
assert.Equal(t, wfv1.WorkflowSucceeded, status.Phase)
524+
nodeJob1 := status.Nodes.FindByDisplayName("job1")
525+
if assert.NotNil(t, nodeJob1) {
526+
assert.Equal(t, wfv1.NodeSucceeded, nodeJob1.Phase)
527+
}
528+
// job2 is skipped because job1 succeeded (not failed)
529+
nodeJob2 := status.Nodes.FindByDisplayName("job2")
530+
if assert.NotNil(t, nodeJob2) {
531+
assert.Equal(t, wfv1.NodeSkipped, nodeJob2.Phase)
532+
}
533+
// job2-error-handler runs: job2 output resolves to "" so "" != "SUCCESS" is true
534+
nodeHandler := status.Nodes.FindByDisplayName("job2-error-handler")
535+
if assert.NotNil(t, nodeHandler) {
536+
assert.Equal(t, wfv1.NodeSucceeded, nodeHandler.Phase)
537+
}
538+
})
539+
}
540+
515541
func (s *FunctionalSuite) TestStepsWhenExprFilter() {
516542
s.Given().
517543
Workflow("@functional/steps-when-expr-filter.yaml").

workflow/controller/steps.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ func (woc *wfOperationCtx) executeSteps(ctx context.Context, nodeName string, tm
163163
woc.buildLocalScope(stepsCtx.scope, prefix, sgNode)
164164
} else {
165165
woc.buildLocalScope(stepsCtx.scope, prefix, childNode)
166+
167+
if (childNode.Phase == wfv1.NodeSkipped || childNode.Phase == wfv1.NodeOmitted) && childNode.Outputs == nil {
168+
var resolvedTmpl *wfv1.Template
169+
_, resolvedTmpl, _, err = stepsCtx.tmplCtx.ResolveTemplate(ctx, &step)
170+
if err == nil && resolvedTmpl != nil {
171+
for _, param := range resolvedTmpl.Outputs.Parameters {
172+
key := fmt.Sprintf("%s.outputs.parameters.%s", prefix, param.Name)
173+
stepsCtx.scope.addParamToScope(key, "")
174+
}
175+
if resolvedTmpl.Outputs.Result != nil {
176+
stepsCtx.scope.addParamToScope(fmt.Sprintf("%s.outputs.result", prefix), "")
177+
}
178+
}
179+
}
166180
}
167181
}
168182
}

0 commit comments

Comments
 (0)