Skip to content

Commit 23eda86

Browse files
gcp-cherry-pick-bot[bot]isubasingheJoibel
authored
fix: ignore failing resolveArt when Art is optional. Fixes #14267 (cherry-pick #14503) (#14521)
Signed-off-by: isubasinghe <[email protected]> Signed-off-by: Alan Clucas <[email protected]> Co-authored-by: Isitha Subasinghe <[email protected]> Co-authored-by: Alan Clucas <[email protected]>
1 parent 89417c3 commit 23eda86

File tree

3 files changed

+131
-6
lines changed

3 files changed

+131
-6
lines changed

workflow/controller/dag.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,11 @@ func (woc *wfOperationCtx) resolveDependencyReferences(dagCtx *dagContext, task
730730
return &newTask, nil
731731
}
732732

733+
artifacts := wfv1.Artifacts{}
733734
// replace all artifact references
734-
for j, art := range newTask.Arguments.Artifacts {
735-
if art.From == "" {
735+
for _, art := range newTask.Arguments.Artifacts {
736+
if art.From == "" && art.FromExpression == "" {
737+
artifacts = append(artifacts, art)
736738
continue
737739
}
738740
resolvedArt, err := scope.resolveArtifact(&art)
@@ -744,8 +746,9 @@ func (woc *wfOperationCtx) resolveDependencyReferences(dagCtx *dagContext, task
744746
return nil, err
745747
}
746748
resolvedArt.Name = art.Name
747-
newTask.Arguments.Artifacts[j] = *resolvedArt
749+
artifacts = append(artifacts, *resolvedArt)
748750
}
751+
newTask.Arguments.Artifacts = artifacts
749752
return &newTask, nil
750753
}
751754

workflow/controller/operator_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11491,3 +11491,123 @@ func TestGetOutboundNodesFromDAGContainerset(t *testing.T) {
1149111491
}
1149211492
assert.True(t, found)
1149311493
}
11494+
11495+
const withItemsOptionalArtStepsWF = `apiVersion: argoproj.io/v1alpha1
11496+
kind: Workflow
11497+
metadata:
11498+
name: fail-optional-artifact-with-items
11499+
spec:
11500+
entrypoint: artifact-example
11501+
templates:
11502+
- name: artifact-example
11503+
steps:
11504+
- - name: generate-artifact
11505+
template: whalesay
11506+
- - name: consume-artifact
11507+
template: print-message
11508+
arguments:
11509+
artifacts:
11510+
- name: message
11511+
optional: true
11512+
from: "{{steps.generate-artifact.outputs.artifacts.message}}"
11513+
withItems:
11514+
- hello world
11515+
11516+
- name: whalesay
11517+
container:
11518+
image: argoproj/argosay:v1
11519+
command: [sh, -c]
11520+
args: ["sleep 1;"]
11521+
outputs:
11522+
artifacts:
11523+
- name: message
11524+
optional: true
11525+
path: /tmp/hello_world
11526+
11527+
11528+
- name: print-message
11529+
inputs:
11530+
artifacts:
11531+
- name: message
11532+
optional: true
11533+
path: /tmp/message
11534+
container:
11535+
image: alpine:latest
11536+
command: [sh, -c]
11537+
args: ["test -e /tmp/message && ls /tmp/message || echo 0"]`
11538+
11539+
func TestWithItemsOptionalArtStepsWF(t *testing.T) {
11540+
wf := wfv1.MustUnmarshalWorkflow(withItemsOptionalArtStepsWF)
11541+
cancel, controller := newController(wf)
11542+
defer cancel()
11543+
11544+
ctx := context.Background()
11545+
woc := newWorkflowOperationCtx(wf, controller)
11546+
woc.operate(ctx)
11547+
makePodsPhase(ctx, woc, apiv1.PodSucceeded)
11548+
woc.operate(ctx)
11549+
node := woc.wf.Status.Nodes.FindByDisplayName("consume-artifact(0:hello world)")
11550+
require.NotNil(t, node)
11551+
assert.Equal(t, wfv1.NodePending, node.Phase)
11552+
}
11553+
11554+
const withItemsOptionalArtDAGWF = `apiVersion: argoproj.io/v1alpha1
11555+
kind: Workflow
11556+
metadata:
11557+
name: fail-optional-artifact-with-items-dag
11558+
spec:
11559+
entrypoint: artifact-example
11560+
templates:
11561+
- name: artifact-example
11562+
dag:
11563+
tasks:
11564+
- name: generate-artifact
11565+
template: whalesay
11566+
- name: consume-artifact
11567+
template: print-message
11568+
dependencies: [generate-artifact]
11569+
arguments:
11570+
artifacts:
11571+
- name: message
11572+
optional: true
11573+
from: "{{tasks.generate-artifact.outputs.artifacts.message}}"
11574+
withItems:
11575+
- hello world
11576+
11577+
- name: whalesay
11578+
container:
11579+
image: argoproj/argosay:v1
11580+
command: [sh, -c]
11581+
args: ["sleep 1;"]
11582+
outputs:
11583+
artifacts:
11584+
- name: message
11585+
optional: true
11586+
path: /tmp/hello_world
11587+
11588+
11589+
- name: print-message
11590+
inputs:
11591+
artifacts:
11592+
- name: message
11593+
optional: true
11594+
path: /tmp/message
11595+
container:
11596+
image: alpine:latest
11597+
command: [sh, -c]
11598+
args: ["test -e /tmp/message && ls /tmp/message || echo 0"]`
11599+
11600+
func TestWithItemsOptionalArtDAGWF(t *testing.T) {
11601+
wf := wfv1.MustUnmarshalWorkflow(withItemsOptionalArtDAGWF)
11602+
cancel, controller := newController(wf)
11603+
defer cancel()
11604+
11605+
ctx := context.Background()
11606+
woc := newWorkflowOperationCtx(wf, controller)
11607+
woc.operate(ctx)
11608+
makePodsPhase(ctx, woc, apiv1.PodSucceeded)
11609+
woc.operate(ctx)
11610+
node := woc.wf.Status.Nodes.FindByDisplayName("consume-artifact(0:hello world)")
11611+
require.NotNil(t, node)
11612+
assert.Equal(t, wfv1.NodePending, node.Phase)
11613+
}

workflow/controller/steps.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,11 @@ func (woc *wfOperationCtx) resolveReferences(stepGroup []wfv1.WorkflowStep, scop
464464
return nil
465465
}
466466

467+
artifacts := wfv1.Artifacts{}
467468
// Step 2: replace all artifact references
468-
for j, art := range newStep.Arguments.Artifacts {
469+
for _, art := range newStep.Arguments.Artifacts {
469470
if art.From == "" && art.FromExpression == "" {
471+
artifacts = append(artifacts, art)
470472
continue
471473
}
472474

@@ -478,9 +480,9 @@ func (woc *wfOperationCtx) resolveReferences(stepGroup []wfv1.WorkflowStep, scop
478480
return fmt.Errorf("unable to resolve references: %s", err)
479481
}
480482
resolvedArt.Name = art.Name
481-
newStep.Arguments.Artifacts[j] = *resolvedArt
483+
artifacts = append(artifacts, *resolvedArt)
482484
}
483-
485+
newStep.Arguments.Artifacts = artifacts
484486
newStepGroup[i] = newStep
485487
return nil
486488
}

0 commit comments

Comments
 (0)