From 5b4b8f6007f4b70dd2aeafabc8be5a3f79674ec7 Mon Sep 17 00:00:00 2001 From: shuangkun tian <72060326+shuangkun@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:55:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20output=20artifact=20of=20steps?= =?UTF-8?q?=20from=20expression=20when=20it=20refers=20=E2=80=A6=20(#12320?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shuangkun Co-authored-by: zjgemi --- workflow/controller/controller_test.go | 48 ++++++++++++++++++++++++++ workflow/controller/scope.go | 8 ++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/workflow/controller/controller_test.go b/workflow/controller/controller_test.go index 33ae3c7e9b19..15468eb444e5 100644 --- a/workflow/controller/controller_test.go +++ b/workflow/controller/controller_test.go @@ -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 @@ -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) +} diff --git a/workflow/controller/scope.go b/workflow/controller/scope.go index 103f8816ee96..42ce5356c7cd 100644 --- a/workflow/controller/scope.go +++ b/workflow/controller/scope.go @@ -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 != "" {