Skip to content

Commit

Permalink
feat: add overridable default input artifacts #2026 (#7647)
Browse files Browse the repository at this point in the history
Signed-off-by: isubasinghe <isubasinghe@student.unimelb.edu.au>
  • Loading branch information
isubasinghe authored Jan 26, 2022
1 parent 17342ba commit b7cd2f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
8 changes: 3 additions & 5 deletions workflow/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,10 @@ func ProcessArgs(tmpl *wfv1.Template, args wfv1.ArgumentsProvider, globalParams,
// Performs substitutions of input artifacts
artifacts := newTmpl.Inputs.Artifacts
for i, inArt := range artifacts {
// if artifact has hard-wired location, we prefer that
if inArt.HasLocationOrKey() {
continue
}

argArt := args.GetArtifactByName(inArt.Name)
if !inArt.Optional {

if !inArt.Optional && !inArt.HasLocationOrKey() {
// artifact must be supplied
if argArt == nil {
return nil, errors.Errorf(errors.CodeBadRequest, "inputs.artifacts.%s was not supplied", inArt.Name)
Expand Down
36 changes: 36 additions & 0 deletions workflow/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,39 @@ func TestIsDone(t *testing.T) {
},
}}))
}

func TestOverridableDefaultInputArts(t *testing.T) {
tmpl := wfv1.Template{}
tmpl.Name = "artifact-printing"

art := wfv1.Artifact{}
art.Name = "overridable-art"
rawArt := wfv1.RawArtifact{}
rawArt.Data = "default contents"
art.Raw = &rawArt
tmpl.Inputs.Artifacts = []wfv1.Artifact{art}

inputs := wfv1.Inputs{}

inputArt := wfv1.Artifact{}
inputArt.Name = art.Name
inputRawArt := wfv1.RawArtifact{}
inputRawArt.Data = "replacement contents"
inputArt.Raw = &inputRawArt

inputs.Artifacts = []wfv1.Artifact{}

globalParams := make(map[string]string)
localParams := make(map[string]string)

newTmpl, err := ProcessArgs(&tmpl, &inputs, globalParams, localParams, false, "", nil)
assert.Nil(t, err)
assert.NotNil(t, newTmpl)
assert.Equal(t, newTmpl.Inputs.Artifacts[0].Raw.Data, rawArt.Data)

inputs.Artifacts = []wfv1.Artifact{inputArt}
newTmpl, err = ProcessArgs(&tmpl, &inputs, globalParams, localParams, false, "", nil)
assert.Nil(t, err)
assert.NotNil(t, newTmpl)
assert.Equal(t, newTmpl.Inputs.Artifacts[0].Raw.Data, inputRawArt.Data)
}

0 comments on commit b7cd2f5

Please sign in to comment.