Skip to content

Commit

Permalink
fix: resolve output artifact of steps from expression when it refers … (
Browse files Browse the repository at this point in the history
#12320)

Signed-off-by: shuangkun <tsk2013uestc@163.com>
Co-authored-by: zjgemi <liuxin_zijian@163.com>
  • Loading branch information
2 people authored and sarabala1979 committed Jan 9, 2024
1 parent 5568a25 commit cc88116
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
48 changes: 48 additions & 0 deletions workflow/controller/controller_test.go
Expand Up @@ -64,6 +64,35 @@ spec:
args: ["hello world"]
`

var fromExrpessingWf = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: from-expression
spec:
entrypoint: main
arguments:
artifacts:
- name: foo
raw:
data: |
Hello
templates:
- name: main
inputs:
artifacts:
- name: foo
steps:
- - name: hello
inline:
container:
image: docker/whalesay:latest
outputs:
artifacts:
- name: result
fromExpression: "1 == 1 ? inputs.artifacts.foo : inputs.artifacts.foo"
`

var helloDaemonWf = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down Expand Up @@ -1103,3 +1132,22 @@ spec:
assert.NoError(t, err)
assert.Len(t, pods.Items, 0)
}

func TestWorkflowReferItselfFromExpression(t *testing.T) {
wf := wfv1.MustUnmarshalWorkflow(fromExrpessingWf)
cancel, controller := newController(wf)
defer cancel()

ctx := context.Background()
assert.True(t, controller.processNextItem(ctx))

woc := newWorkflowOperationCtx(wf, controller)
woc.operate(ctx)
assert.Equal(t, wfv1.WorkflowRunning, woc.wf.Status.Phase)
makePodsPhase(ctx, woc, apiv1.PodSucceeded)

woc.operate(ctx)
assert.True(t, controller.processNextPodCleanupItem(ctx))
assert.True(t, controller.processNextPodCleanupItem(ctx))
assert.Equal(t, wfv1.WorkflowSucceeded, woc.wf.Status.Phase)
}
8 changes: 7 additions & 1 deletion workflow/controller/scope.go
Expand Up @@ -103,7 +103,13 @@ func (s *wfScope) resolveArtifact(art *wfv1.Artifact) (*wfv1.Artifact, error) {
}
valArt, ok := val.(wfv1.Artifact)
if !ok {
return nil, errors.Errorf(errors.CodeBadRequest, "Variable {{%v}} is not an artifact", art)
//If the workflow refers itself input artifacts in fromExpression, the val type is "*wfv1.Artifact"
ptArt, ok := val.(*wfv1.Artifact)
if ok {
valArt = *ptArt
} else {
return nil, errors.Errorf(errors.CodeBadRequest, "Variable {{%v}} is not an artifact", art)
}
}

if art.SubPath != "" {
Expand Down

0 comments on commit cc88116

Please sign in to comment.