-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template_level_volume example (#954)
* Upstream example but only appears in docs so is not part of the usual collection * User in slack was asking how to recreate this example, see https://cloud-native.slack.com/archives/C03NRMD9KPY/p1707226500216859 Signed-off-by: Elliot Gunton <[email protected]>
- Loading branch information
1 parent
34d1569
commit 7e0dcbe
Showing
5 changed files
with
433 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# Template Level Volume | ||
|
||
|
||
|
||
This is an upstream example that only appears in the docs. | ||
|
||
See https://argo-workflows.readthedocs.io/en/latest/walk-through/volumes/ | ||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import ( | ||
Container, | ||
ExistingVolume, | ||
Parameter, | ||
Resource, | ||
Step, | ||
Steps, | ||
Workflow, | ||
) | ||
|
||
with Workflow( | ||
generate_name="template-level-volume-", | ||
entrypoint="generate-and-use-volume", | ||
) as w: | ||
generate_volume = Resource( | ||
name="generate-volume", | ||
inputs=[Parameter(name="pvc-size")], | ||
outputs=[Parameter(name="pvc-name", value_from={"jsonPath": "{.metadata.name}"})], | ||
action="create", | ||
set_owner_reference=True, | ||
manifest="""apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
generateName: pvc-example- | ||
spec: | ||
accessModes: ['ReadWriteOnce', 'ReadOnlyMany'] | ||
resources: | ||
requests: | ||
storage: '{{inputs.parameters.pvc-size}}' | ||
""", | ||
) | ||
whalesay = Container( | ||
name="whalesay", | ||
inputs=[Parameter(name="pvc-name")], | ||
volumes=[ExistingVolume(name="workdir", claim_name="{{inputs.parameters.pvc-name}}", mount_path="/mnt/vol")], | ||
image="docker/whalesay:latest", | ||
command=["sh", "-c"], | ||
args=["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"], | ||
) | ||
print_message = Container( | ||
name="print-message", | ||
inputs=[Parameter(name="pvc-name")], | ||
volumes=[ExistingVolume(name="workdir", claim_name="{{inputs.parameters.pvc-name}}", mount_path="/mnt/vol")], | ||
image="alpine:latest", | ||
command=["sh", "-c"], | ||
args=["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"], | ||
) | ||
with Steps(name="generate-and-use-volume") as s: | ||
generate_vol_step: Step = generate_volume(name="generate-volume", arguments={"pvc-size": "1Gi"}) | ||
whalesay(name="generate", arguments=generate_vol_step.get_parameter("pvc-name")) | ||
print_message(name="print", arguments=generate_vol_step.get_parameter("pvc-name")) | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: template-level-volume- | ||
spec: | ||
entrypoint: generate-and-use-volume | ||
templates: | ||
- name: generate-and-use-volume | ||
steps: | ||
- - name: generate-volume | ||
template: generate-volume | ||
arguments: | ||
parameters: | ||
- name: pvc-size | ||
# In a real-world example, this could be generated by a previous workflow step. | ||
value: '1Gi' | ||
- - name: generate | ||
template: whalesay | ||
arguments: | ||
parameters: | ||
- name: pvc-name | ||
value: '{{steps.generate-volume.outputs.parameters.pvc-name}}' | ||
- - name: print | ||
template: print-message | ||
arguments: | ||
parameters: | ||
- name: pvc-name | ||
value: '{{steps.generate-volume.outputs.parameters.pvc-name}}' | ||
|
||
- name: generate-volume | ||
inputs: | ||
parameters: | ||
- name: pvc-size | ||
resource: | ||
action: create | ||
setOwnerReference: true | ||
manifest: | | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
generateName: pvc-example- | ||
spec: | ||
accessModes: ['ReadWriteOnce', 'ReadOnlyMany'] | ||
resources: | ||
requests: | ||
storage: '{{inputs.parameters.pvc-size}}' | ||
outputs: | ||
parameters: | ||
- name: pvc-name | ||
valueFrom: | ||
jsonPath: '{.metadata.name}' | ||
|
||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: pvc-name | ||
volumes: | ||
- name: workdir | ||
persistentVolumeClaim: | ||
claimName: '{{inputs.parameters.pvc-name}}' | ||
container: | ||
image: docker/whalesay:latest | ||
command: [sh, -c] | ||
args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"] | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /mnt/vol | ||
|
||
- name: print-message | ||
inputs: | ||
parameters: | ||
- name: pvc-name | ||
volumes: | ||
- name: workdir | ||
persistentVolumeClaim: | ||
claimName: '{{inputs.parameters.pvc-name}}' | ||
container: | ||
image: alpine:latest | ||
command: [sh, -c] | ||
args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"] | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /mnt/vol | ||
``` | ||
|
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,83 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: template-level-volume- | ||
spec: | ||
entrypoint: generate-and-use-volume | ||
templates: | ||
- name: generate-and-use-volume | ||
steps: | ||
- - name: generate-volume | ||
template: generate-volume | ||
arguments: | ||
parameters: | ||
- name: pvc-size | ||
# In a real-world example, this could be generated by a previous workflow step. | ||
value: '1Gi' | ||
- - name: generate | ||
template: whalesay | ||
arguments: | ||
parameters: | ||
- name: pvc-name | ||
value: '{{steps.generate-volume.outputs.parameters.pvc-name}}' | ||
- - name: print | ||
template: print-message | ||
arguments: | ||
parameters: | ||
- name: pvc-name | ||
value: '{{steps.generate-volume.outputs.parameters.pvc-name}}' | ||
|
||
- name: generate-volume | ||
inputs: | ||
parameters: | ||
- name: pvc-size | ||
resource: | ||
action: create | ||
setOwnerReference: true | ||
manifest: | | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
generateName: pvc-example- | ||
spec: | ||
accessModes: ['ReadWriteOnce', 'ReadOnlyMany'] | ||
resources: | ||
requests: | ||
storage: '{{inputs.parameters.pvc-size}}' | ||
outputs: | ||
parameters: | ||
- name: pvc-name | ||
valueFrom: | ||
jsonPath: '{.metadata.name}' | ||
|
||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: pvc-name | ||
volumes: | ||
- name: workdir | ||
persistentVolumeClaim: | ||
claimName: '{{inputs.parameters.pvc-name}}' | ||
container: | ||
image: docker/whalesay:latest | ||
command: [sh, -c] | ||
args: ["echo generating message in volume; cowsay hello world | tee /mnt/vol/hello_world.txt"] | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /mnt/vol | ||
|
||
- name: print-message | ||
inputs: | ||
parameters: | ||
- name: pvc-name | ||
volumes: | ||
- name: workdir | ||
persistentVolumeClaim: | ||
claimName: '{{inputs.parameters.pvc-name}}' | ||
container: | ||
image: alpine:latest | ||
command: [sh, -c] | ||
args: ["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"] | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /mnt/vol |
Oops, something went wrong.