Skip to content

Volumes Pvc

Note

This example is a replication of an Argo Workflow example in Hera. The upstream example can be found here.

from hera.workflows import Container, Steps, Volume, Workflow

with Workflow(generate_name="volumes-pvc-", entrypoint="volumes-pvc-example") as w:
    v = Volume(name="workdir", size="1Gi", mount_path="/mnt/vol")
    hello_world_to_file = Container(
        name="hello-world-to-file",
        image="busybox",
        command=["sh", "-c"],
        args=["echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt"],
        volumes=v,
    )
    print_message_from_file = Container(
        name="print-message-from-file",
        image="alpine:latest",
        command=["sh", "-c"],
        args=["echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt"],
        volumes=v,
    )
    with Steps(name="volumes-pvc-example") as s:
        hello_world_to_file(name="generate")
        print_message_from_file(name="print")
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: volumes-pvc-
spec:
  entrypoint: volumes-pvc-example
  templates:
  - name: hello-world-to-file
    container:
      image: busybox
      args:
      - echo generating message in volume; echo hello world | tee /mnt/vol/hello_world.txt
      command:
      - sh
      - -c
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol
  - name: print-message-from-file
    container:
      image: alpine:latest
      args:
      - echo getting message from volume; find /mnt/vol; cat /mnt/vol/hello_world.txt
      command:
      - sh
      - -c
      volumeMounts:
      - name: workdir
        mountPath: /mnt/vol
  - name: volumes-pvc-example
    steps:
    - - name: generate
        template: hello-world-to-file
    - - name: print
        template: print-message-from-file
  volumeClaimTemplates:
  - metadata:
      name: workdir
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi

Comments