argoproj / argoproj/argo-workflows

`fromExpression` should also work in `arguments.artifacts`, not just `outputs.artifacts`

Open
#6,207 5 comments 9 reactions 0 assignees View on GitHub
area/spec area/templating
Dominant language
Go
Stars
17k
Forks
3.7k
Avg merge
1d 20h
Merged PRs (30d)
138

Description

# Summary

I'm rolling out v3.1.0's fromExpression to my templates and workflows and encountered a use case that I expected to work but which did not: Using a complicated expression to define arguments for subsequent steps/tasks.

# Use Cases

Consider the following simple example, very similar in nature to the primary example of [conditional artifacts](https://argoproj.github.io/argo-workflows/examples/conditional-artifacts.yaml):

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: from-expression-
spec:
entrypoint: coinflip
templates:
- name: coinflip
steps:
- - name: flip-coin
template: flip-coin
- - name: heads
template: heads
when: "{{steps.flip-coin.outputs.result}} == heads"
- name: tails
template: tails
when: "{{steps.flip-coin.outputs.result}} == tails"
- - name: message-result
template: print-message
arguments:
artifacts:
- name: message
fromExpression: >
steps['flip-coin'].outputs.result == 'heads' ?
steps.heads.outputs.artifacts.result :
steps.tails.outputs.artifacts.result

- name: flip-coin
script:
image: python:alpine3.6
command: [ python ]
source: |
import random
print("heads" if random.randint(0,1) == 0 else "tails")

- name: heads
script:
image: python:alpine3.6
command: [ python ]
source: |
with open("result.txt", "w") as f:
f.write("it was heads")
outputs:
artifacts:
- name: result
path: /result.txt

- name: tails
script:
image: python:alpine3.6
command: [ python ]
source: |
with open("result.txt", "w") as f:
f.write("it was tails")
outputs:
artifacts:
- name: result
path: /result.txt

- name: print-message
inputs:
artifacts:
- name: message
path: /tmp/message
container:
image: alpine:latest
command: [sh, -c]
args: ["cat /tmp/message"]
```

Instead of defining the output to the overall step, I would like this output to be used in a subsequent step.

However, the linter doesn't like this:
```
Failed to submit workflow: templates.coinflip.steps[2].message-result.arguments.message.from, artifact location, or key is required
```

Of course, I could encapsulate the first three steps into a single step use this expression in the output there. But forcing encapsulation is an additional cost with all of the arguments that must be passed up and down.

---

**Message from the maintainers**:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files or tests. Start by reproducing the linter error with the supplied workflow YAML, then trace validation of arguments.artifacts and compare it with outputs.artifacts handling. Done means the fromExpression artifact argument is accepted and the example validates without requiring a location or key.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.