Skip to content

Commit

Permalink
docs: Add example of recursive for loop (argoproj#2801)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 committed Apr 23, 2020
1 parent 29d39e2 commit a2d2b84
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Workflow is the definition of a workflow resource

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -428,6 +430,8 @@ WorkflowSpec is the specification of a Workflow.

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -712,6 +716,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -962,6 +968,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -1132,6 +1140,8 @@ Arguments to a template

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`scripts-bash.yaml`](../examples/scripts-bash.yaml)
Expand Down Expand Up @@ -1372,6 +1382,8 @@ Template is a reusable and composable unit of execution in a workflow

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -1741,6 +1753,8 @@ Parameter indicate a passed string parameter to a service template with an optio

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`scripts-bash.yaml`](../examples/scripts-bash.yaml)
Expand Down Expand Up @@ -1986,6 +2000,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem

- [`pod-spec-from-previous-step.yaml`](../examples/pod-spec-from-previous-step.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`scripts-bash.yaml`](../examples/scripts-bash.yaml)
Expand Down Expand Up @@ -2169,6 +2185,8 @@ Pod metdata

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -2332,6 +2350,8 @@ ScriptTemplate is a template subtype to enable scripting through code steps

- [`pod-spec-from-previous-step.yaml`](../examples/pod-spec-from-previous-step.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`retry-script.yaml`](../examples/retry-script.yaml)

- [`scripts-bash.yaml`](../examples/scripts-bash.yaml)
Expand Down Expand Up @@ -2435,6 +2455,8 @@ WorkflowStep is a reference to a template to execute in a series of step

- [`pod-metadata.yaml`](../examples/pod-metadata.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -3279,6 +3301,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down Expand Up @@ -4104,6 +4128,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devicesand

- [`pod-spec-yaml-patch.yaml`](../examples/pod-spec-yaml-patch.yaml)

- [`recursive-for-loop.yaml`](../examples/recursive-for-loop.yaml)

- [`resource-delete-with-flags.yaml`](../examples/resource-delete-with-flags.yaml)

- [`resource-flags.yaml`](../examples/resource-flags.yaml)
Expand Down
50 changes: 50 additions & 0 deletions examples/recursive-for-loop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This example illustrates how to iterate serially over a sequence using a counter.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: recursive-loop-
spec:
entrypoint: plan
templates:
- name: plan
steps:
- - name: recurse
template: loop
arguments:
parameters:
- name: counter
value: 0
- name: limit
value: 10
- name: loop
inputs:
parameters:
- name: counter
- name: limit
steps:
- - name: iterate-counter
template: counter-iteration
arguments:
parameters:
- name: counter
value: "{{inputs.parameters.counter}}"
- - name: continue
template: loop
when: "{{steps.iterate-counter.outputs.result}} < {{inputs.parameters.limit}}"
arguments:
parameters:
- name: counter
value: "{{steps.iterate-counter.outputs.result}}"
- name: limit
value: "{{inputs.parameters.limit}}"
- name: counter-iteration
inputs:
parameters:
- name: counter
script:
image: python:alpine3.6
command: [python]
source: |
print({{inputs.parameters.counter}} + 1)

0 comments on commit a2d2b84

Please sign in to comment.