-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix templateRef and clean up examples (#496)
Signed-off-by: GitHub <[email protected]>
- Loading branch information
1 parent
506e960
commit af27524
Showing
28 changed files
with
566 additions
and
81 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Steps Inline Workflow | ||
|
||
> Note: This example is a replication of an Argo Workflow example in Hera. The upstream example can be [found here](https://github.com/argoproj/argo-workflows/blob/master/examples/steps-inline-workflow.yaml). | ||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import Container, Step, Steps, Workflow | ||
|
||
container = Container(image="argoproj/argosay:v2") | ||
|
||
with Workflow( | ||
generate_name="steps-inline-", | ||
entrypoint="main", | ||
annotations={ | ||
"workflows.argoproj.io/description": ("This workflow demonstrates running a steps with inline templates."), | ||
"workflows.argoproj.io/version": ">= 3.2.0", | ||
}, | ||
) as w: | ||
with Steps(name="main"): | ||
Step(name="a", inline=container) | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
annotations: | ||
workflows.argoproj.io/description: This workflow demonstrates running a steps | ||
with inline templates. | ||
workflows.argoproj.io/version: '>= 3.2.0' | ||
generateName: steps-inline- | ||
spec: | ||
entrypoint: main | ||
templates: | ||
- name: main | ||
steps: | ||
- - inline: | ||
container: | ||
image: argoproj/argosay:v2 | ||
name: a | ||
``` |
72 changes: 72 additions & 0 deletions
72
docs/examples/workflows/upstream/workflow_template__dag.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Workflow Template Dag | ||
|
||
> Note: This example is a replication of an Argo Workflow example in Hera. The upstream example can be [found here](https://github.com/argoproj/argo-workflows/blob/master/examples/workflow-template/dag.yaml). | ||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import DAG, Task, Workflow | ||
from hera.workflows.models import TemplateRef | ||
|
||
with Workflow( | ||
generate_name="workflow-template-dag-diamond-", | ||
entrypoint="diamond", | ||
) as w: | ||
whalesay_template_ref = TemplateRef(name="workflow-template-whalesay-template", template="whalesay-template") | ||
inner_template_ref = TemplateRef(name="workflow-template-inner-dag", template="inner-diamond") | ||
with DAG(name="diamond"): | ||
A = Task(name="A", template_ref=whalesay_template_ref, arguments={"message": "A"}) | ||
B = Task(name="B", template_ref=whalesay_template_ref, arguments={"message": "B"}) | ||
C = Task(name="C", template_ref=inner_template_ref) | ||
D = Task(name="D", template_ref=whalesay_template_ref, arguments={"message": "D"}) | ||
|
||
A >> [B, C] >> D | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: workflow-template-dag-diamond- | ||
spec: | ||
entrypoint: diamond | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: A | ||
name: A | ||
templateRef: | ||
name: workflow-template-whalesay-template | ||
template: whalesay-template | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: B | ||
depends: A | ||
name: B | ||
templateRef: | ||
name: workflow-template-whalesay-template | ||
template: whalesay-template | ||
- depends: A | ||
name: C | ||
templateRef: | ||
name: workflow-template-inner-dag | ||
template: inner-diamond | ||
- arguments: | ||
parameters: | ||
- name: message | ||
value: D | ||
depends: B && C | ||
name: D | ||
templateRef: | ||
name: workflow-template-whalesay-template | ||
template: whalesay-template | ||
name: diamond | ||
``` |
49 changes: 49 additions & 0 deletions
49
docs/examples/workflows/upstream/workflow_template__hello_world.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Workflow Template Hello World | ||
|
||
> Note: This example is a replication of an Argo Workflow example in Hera. The upstream example can be [found here](https://github.com/argoproj/argo-workflows/blob/master/examples/workflow-template/hello-world.yaml). | ||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import Step, Steps, Workflow | ||
from hera.workflows.models import TemplateRef | ||
|
||
with Workflow( | ||
generate_name="workflow-template-hello-world-", | ||
entrypoint="whalesay", | ||
) as w: | ||
whalesay_template_ref = TemplateRef( | ||
name="workflow-template-whalesay-template", | ||
template="whalesay-template", | ||
) | ||
with Steps(name="whalesay"): | ||
Step( | ||
name="call-whalesay-template", | ||
template_ref=whalesay_template_ref, | ||
arguments={"message": "hello world"}, | ||
) | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: workflow-template-hello-world- | ||
spec: | ||
entrypoint: whalesay | ||
templates: | ||
- name: whalesay | ||
steps: | ||
- - arguments: | ||
parameters: | ||
- name: message | ||
value: hello world | ||
name: call-whalesay-template | ||
templateRef: | ||
name: workflow-template-whalesay-template | ||
template: whalesay-template | ||
``` |
32 changes: 32 additions & 0 deletions
32
docs/examples/workflows/upstream/workflow_template__workflow_template_ref.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Workflow Template Workflow Template Ref | ||
|
||
> Note: This example is a replication of an Argo Workflow example in Hera. The upstream example can be [found here](https://github.com/argoproj/argo-workflows/blob/master/examples/workflow-template/workflow-template-ref.yaml). | ||
|
||
|
||
## Hera | ||
|
||
```python | ||
from hera.workflows import Workflow | ||
from hera.workflows.models import WorkflowTemplateRef | ||
|
||
wt_ref = WorkflowTemplateRef(name="workflow-template-submittable") | ||
|
||
with Workflow( | ||
generate_name="workflow-template-hello-world-", | ||
workflow_template_ref=wt_ref, | ||
) as w: | ||
pass | ||
``` | ||
|
||
## YAML | ||
|
||
```yaml | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: workflow-template-hello-world- | ||
spec: | ||
workflowTemplateRef: | ||
name: workflow-template-submittable | ||
``` |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# The coinflip example combines the use of a script result, | ||
# along with conditionals, to take a dynamic path in the | ||
# workflow. In this example, depending on the result of the | ||
# first step, 'flip-coin', the template will either run the | ||
# 'heads' step or the 'tails' step. | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: coinflip- | ||
annotations: | ||
workflows.argoproj.io/description: | | ||
This is an example of coin flip defined as a sequence of conditional steps. | ||
You can also run it in Python: https://couler-proj.github.io/couler/examples/#coin-flip | ||
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: flip-coin | ||
script: | ||
image: python:alpine3.6 | ||
command: [python] | ||
source: | | ||
import random | ||
result = "heads" if random.randint(0,1) == 0 else "tails" | ||
print(result) | ||
- name: heads | ||
container: | ||
image: alpine:3.6 | ||
command: [sh, -c] | ||
args: ["echo \"it was heads\""] | ||
|
||
- name: tails | ||
container: | ||
image: alpine:3.6 | ||
command: [sh, -c] | ||
args: ["echo \"it was tails\""] |
Oops, something went wrong.