Last active
October 7, 2019 07:29
-
-
Save dtaniwaki/c6ccf9e5d9ef04bdd4962c76429cf6db to your computer and use it in GitHub Desktop.
A concrete failure case for https://github.com/argoproj/argo/pull/1651
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example workflow to demonstrate parameter aggregation. | |
apiVersion: argoproj.io/v1alpha1 | |
kind: WorkflowTemplate | |
metadata: | |
name: parameter-aggregation-template | |
spec: | |
templates: | |
# odd-or-even accepts a number and returns whether or not that number is odd or even | |
- name: odd-or-even | |
inputs: | |
parameters: | |
- name: num | |
container: | |
image: alpine:latest | |
command: [sh, -xc] | |
args: | |
- | | |
sleep 1 && | |
echo {{inputs.parameters.num}} > /tmp/num && | |
if [ $(({{inputs.parameters.num}}%2)) -eq 0 ]; then | |
echo "even" > /tmp/even; | |
else | |
echo "odd" > /tmp/even; | |
fi | |
outputs: | |
parameters: | |
- name: num | |
valueFrom: | |
path: /tmp/num | |
- name: evenness | |
valueFrom: | |
path: /tmp/even | |
# divide-by-2 divides a number in half | |
- name: divide-by-2 | |
inputs: | |
parameters: | |
- name: num | |
script: | |
image: alpine:latest | |
command: [sh, -x] | |
source: | | |
#!/bin/sh | |
echo ready | |
sleep 30 | |
echo $(({{inputs.parameters.num}}/2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example workflow to demonstrate parameter aggregation. | |
apiVersion: argoproj.io/v1alpha1 | |
kind: Workflow | |
metadata: | |
generateName: parameter-aggregation- | |
spec: | |
entrypoint: parameter-aggregation | |
templates: | |
- name: parameter-aggregation | |
steps: | |
# First loop through a list of numbers and determine if the number is odd or even. This is | |
# captured in output parameter 'evenness'. (e.g. {"num": "4", "evenness": "even"}) | |
- - name: odd-or-even | |
templateRef: | |
name: parameter-aggregation-template | |
template: odd-or-even | |
arguments: | |
parameters: | |
- name: num | |
value: "{{item}}" | |
withItems: [1, 2, 3, 4] | |
# Next, for each even number, divide it by two (using a script template). | |
# Skip odd numbers using a `when` clause. | |
- - name: divide-by-2 | |
templateRef: | |
name: parameter-aggregation-template | |
template: divide-by-2 | |
arguments: | |
parameters: | |
- name: num | |
value: "{{item.num}}" | |
withParam: "{{steps.odd-or-even.outputs.parameters}}" | |
when: "{{item.evenness}} == even" | |
# Finally, print all numbers processed in the previous step | |
- - name: print | |
template: whalesay | |
arguments: | |
parameters: | |
- name: message | |
value: "{{item}}" | |
withParam: "{{steps.divide-by-2.outputs.result}}" | |
# whalesay prints a number using whalesay | |
- name: whalesay | |
inputs: | |
parameters: | |
- name: message | |
container: | |
image: docker/whalesay:latest | |
command: [cowsay] | |
args: ["{{inputs.parameters.message}}"] |
Author
dtaniwaki
commented
Oct 7, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment