Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for artifact path references #1300

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The following variables are made available to reference various metadata of a wo
| Variable | Description|
|----------|------------|
| `pod.name` | Pod name of the container/script |
| `inputs.artifacts.<NAME>.path` | Local path of the input artifact |
| `outputs.artifacts.<NAME>.path` | Local path of the output artifact |
| `outputs.parameters.<NAME>.path` | Local path of the output parameter |

## Loops (withItems / withParam)
| Variable | Description|
Expand Down
36 changes: 36 additions & 0 deletions examples/artifact-path-placeholders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This example demonstrates the how to refer to input and output artifact paths.
# Referring to the path instead of copy/pasting it prevents errors when paths change.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: artifact-path-placeholders-
spec:
entrypoint: grep
arguments:
parameters:
- name: regex
value: Argo
artifacts:
- name: text
raw:
data: |
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
Beginning with thee, O Phoebus,
I will recount the famous deeds of men of old,
who, at the behest of King Pelias,
down through the mouth of Pontus and between the Cyanean rocks,
sped well-benched Argo in quest of the golden fleece
templates:
- name: grep
inputs:
parameters:
- name: regex
artifacts:
- name: text
path: /inputs/text/data
outputs:
artifacts:
- name: text
path: /outputs/text/data
container:
image: busybox
command: [sh, -c, 'grep "{{inputs.parameters.regex}}" <"{{inputs.artifacts.text.path}}" | tee "{{outputs.artifacts.text.path}}"']
2 changes: 1 addition & 1 deletion workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const (
)

// GlobalVarWorkflowRootTags is a list of root tags in workflow which could be used for variable reference
var GlobalVarValidWorkflowVariablePrefix = []string{"item.", "steps.", "inputs.", "pod.", "workflow.", "tasks."}
var GlobalVarValidWorkflowVariablePrefix = []string{"item.", "steps.", "inputs.", "outputs.", "pod.", "workflow.", "tasks."}

// ExecutionControl contains execution control parameters for executor to decide how to execute the container
type ExecutionControl struct {
Expand Down
16 changes: 16 additions & 0 deletions workflow/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ func substituteParams(tmpl *wfv1.Template, globalParams, localParams map[string]
}
replaceMap["inputs.parameters."+inParam.Name] = *inParam.Value
}
for _, inArt := range globalReplacedTmpl.Inputs.Artifacts {
if inArt.Path != "" {
replaceMap["inputs.artifacts."+inArt.Name+".path"] = inArt.Path
}
}
for _, outArt := range globalReplacedTmpl.Outputs.Artifacts {
if outArt.Path != "" {
replaceMap["outputs.artifacts."+outArt.Name+".path"] = outArt.Path
}
}
for _, param := range globalReplacedTmpl.Outputs.Parameters {
if param.ValueFrom != nil && param.ValueFrom.Path != "" {
replaceMap["outputs.parameters."+param.Name+".path"] = param.ValueFrom.Path
}
}

fstTmpl = fasttemplate.New(globalReplacedTmplStr, "{{", "}}")
s, err := Replace(fstTmpl, replaceMap, true)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ func (ctx *wfValidationCtx) validateTemplate(tmpl *wfv1.Template, args wfv1.Argu
localParams[common.LocalVarPodName] = placeholderValue
scope[common.LocalVarPodName] = placeholderValue
}
if tmpl.IsLeaf() {
for _, art := range tmpl.Outputs.Artifacts {
if art.Path != "" {
scope[fmt.Sprintf("outputs.artifacts.%s.path", art.Name)] = true
}
}
for _, param := range tmpl.Outputs.Parameters {
if param.ValueFrom != nil && param.ValueFrom.Path != "" {
scope[fmt.Sprintf("outputs.parameters.%s.path", param.Name)] = true
}
}
}

_, err = common.ProcessArgs(tmpl, args, ctx.globalParams, localParams, true)
if err != nil {
Expand Down Expand Up @@ -190,6 +202,7 @@ func validateInputs(tmpl *wfv1.Template) (map[string]interface{}, error) {
if art.Path == "" {
return nil, errors.Errorf(errors.CodeBadRequest, "templates.%s.%s.path not specified", tmpl.Name, artRef)
}
scope[fmt.Sprintf("inputs.artifacts.%s.path", art.Name)] = true
} else {
if art.Path != "" {
return nil, errors.Errorf(errors.CodeBadRequest, "templates.%s.%s.path only valid in container/script templates", tmpl.Name, artRef)
Expand Down
56 changes: 56 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,62 @@ func TestUnresolved(t *testing.T) {
}
}

var ioArtifactPaths = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: passthrough-
spec:
entrypoint: passthrough
arguments:
artifacts:
- name: art
raw:
data: Hello World
templates:
- name: passthrough
inputs:
artifacts:
- name: art
path: /inputs/art/data
outputs:
artifacts:
- name: art
path: /outputs/art/data
container:
image: busybox
command: [cp, "{{inputs.artifacts.art.path}}", "{{outputs.artifacts.art.path}}"]
`

func TestResolveIOArtifactPathPlaceholders(t *testing.T) {
err := validate(ioArtifactPaths)
assert.Nil(t, err)
}

var outputParameterPath = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: get-current-date-
spec:
entrypoint: get-current-date
templates:
- name: get-current-date
outputs:
parameters:
- name: current-date
valueFrom:
path: /tmp/current-date
container:
image: busybox
command: [sh, -c, 'date > {{outputs.parameters.current-date.path}}']
`

func TestResolveOutputParameterPathPlaceholder(t *testing.T) {
err := validate(outputParameterPath)
assert.Nil(t, err)
}

var stepOutputReferences = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down