Skip to content

Commit 2434a0c

Browse files
authored
fix(controller): skip empty optional step artifacts (#16839)
Signed-off-by: rwong2888 <rwong@forbes.com>
1 parent bde5adf commit 2434a0c

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

workflow/controller/steps.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ func (woc *wfOperationCtx) resolveReferences(ctx context.Context, stepGroup []wf
535535
}
536536
return fmt.Errorf("unable to resolve references: %w", err)
537537
}
538+
if art.Optional && !resolvedArt.HasLocationOrKey() {
539+
continue
540+
}
538541
resolvedArt.Name = art.Name
539542
artifacts = append(artifacts, *resolvedArt)
540543
}

workflow/controller/steps_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
wfv1 "github.com/argoproj/argo-workflows/v4/pkg/apis/workflow/v1alpha1"
1313
"github.com/argoproj/argo-workflows/v4/util/logging"
1414
"github.com/argoproj/argo-workflows/v4/util/variables"
15+
varkeys "github.com/argoproj/argo-workflows/v4/util/variables/keys"
1516
)
1617

1718
// TestStepsFailedRetries ensures a steps template will recognize exhausted retries
@@ -82,6 +83,28 @@ func TestArtifactResolutionWhenSkipped(t *testing.T) {
8283
assert.Equal(t, wfv1.WorkflowSucceeded, woc.wf.Status.Phase)
8384
}
8485

86+
func TestResolveReferencesSkipsOptionalArtifactFromSkippedStep(t *testing.T) {
87+
ctx := logging.TestContext(t.Context())
88+
woc := newWoc(ctx, wfv1.Workflow{})
89+
scope := createScope(nil)
90+
varkeys.StepsNodeRef.OutputsArtifactByName.Set(scope.scope, wfv1.Artifact{}, "generate", "message")
91+
stepGroup := []wfv1.WorkflowStep{{
92+
Name: "consume",
93+
Template: "consumer",
94+
Arguments: wfv1.Arguments{Artifacts: wfv1.Artifacts{{
95+
Name: "message",
96+
From: "{{steps.generate.outputs.artifacts.message}}",
97+
Optional: true,
98+
}}},
99+
}}
100+
101+
resolvedSteps, err := woc.resolveReferences(ctx, stepGroup, scope)
102+
103+
require.NoError(t, err)
104+
require.Len(t, resolvedSteps, 1)
105+
assert.Empty(t, resolvedSteps[0].Arguments.Artifacts)
106+
}
107+
85108
var stepsWithParamAndGlobalParam = `
86109
apiVersion: argoproj.io/v1alpha1
87110
kind: Workflow

0 commit comments

Comments
 (0)