Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Variables and Artifacts

  • Variables use {{ }}, see workflow-fundamentals.md for the full list
  • Parameters = small scalar values (strings), artifacts = files/dirs

Variables

  • workflow.* - name, namespace, uid, status, creationTimestamp, priority, parameters.<n>
  • steps.<step>.* / tasks.<task>.* - outputs.result, outputs.parameters.<n>, outputs.artifacts.<n>, status, exitCode
  • pod.name - pod running the template
    • anything else about the pod (IP etc) comes from the downward API:
env:
  - name: POD_IP
    valueFrom:
      fieldRef:
        fieldPath: status.podIP

Parameters

Workflow parameters

  • Defined in spec.arguments.parameters, overridable at submit
argo submit workflow.yaml -p environment=production -p version=2.0.0
  • Used as {{workflow.parameters.environment}}

Template inputs

  • value/default gives a default, no default = required
inputs:
  parameters:
    - name: greeting
      value: 'Hello'
    - name: name

Template outputs

  • From a file
outputs:
  parameters:
    - name: id
      valueFrom:
        path: /tmp/id.txt
  • stdout of script/container is outputs.result (no outputs.parameters entry needed)
  • jsonPath extracts from a JSON file
outputs:
  parameters:
    - name: count
      valueFrom:
        path: /tmp/result.json
        jsonPath: '{.count}'
  • valueFrom.default is used if the file is missing

Artifacts

  • Files/dirs passed between steps, stored in the artifact repository

  • Pass with from:

Prune

arguments:
  artifacts:
    - name: input-file
      from: '{{steps.create-file.outputs.artifacts.output-file}}'
  • Inputs can come from a previous step, git, http, s3, gcs, etc.
apiVersion: v1
kind: Secret
metadata:
  name: minio-credentials
  namespace: argo
stringData:
  accesskey: minio
  secretkey: minio123
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: argo
spec:
  ports:
    - port: 9000
  selector:
    app: minio
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: argo
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
        - name: minio
          image: minio/minio:RELEASE.2024-01-13T07-53-03Z
          args: [server, /data]
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: accesskey } }
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: secretkey } }
          ports:
            - containerPort: 9000
          volumeMounts:
            - { name: data, mountPath: /data }
      volumes:
        - name: data
          emptyDir: {}
apiVersion: v1
kind: Secret
metadata:
  name: minio-credentials
  namespace: argo
stringData:
  accesskey: minio
  secretkey: minio123
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: argo
spec:
  ports:
    - port: 9000
  selector:
    app: minio
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: argo
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
        - name: minio
          image: minio/minio:RELEASE.2024-01-13T07-53-03Z
          args: [server, /data]
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: accesskey } }
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: secretkey } }
          ports:
            - containerPort: 9000
          volumeMounts:
            - { name: data, mountPath: /data }
      volumes:
        - name: data
          emptyDir: {}
inputs:
apiVersion: v1
kind: Secret
metadata:
  name: minio-credentials
  namespace: argo
stringData:
  accesskey: minio
  secretkey: minio123
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: argo
spec:
  ports:
    - port: 9000
  selector:
    app: minio
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: argo
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
apiVersion: v1
kind: Secret
metadata:
  name: minio-credentials
  namespace: argo
stringData:
  accesskey: minio
  secretkey: minio123
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: argo
spec:
  ports:
    - port: 9000
  selector:
    app: minio
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: argo
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
        - name: minio
          image: minio/minio:RELEASE.2024-01-13T07-53-03Z
          args: [server, /data]
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: accesskey } }
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: secretkey } }
          ports:
            - containerPort: 9000
          volumeMounts:
            - { name: data, mountPath: /data }
      volumes:
        - name: data
          emptyDir: {}
      containers:
        - name: minio
          image: minio/minio:RELEASE.2024-01-13T07-53-03Z
          args: [server, /data]
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: accesskey } }
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: secretkey } }
          ports:
            - containerPort: 9000
          volumeMounts:
            - { name: data, mountPath: /data }
      volumes:
        - name: data
          emptyDir: {}
  artifacts:
    - name: source-code
      path: /src
      git:
        repo: https://github.com/example/repository.git
        revision: main
        depth: 1
    - name: data-file
      path: /data/file.json
      http:
        url: https://example.com/data.json
    - name: dataset
      path: /data/dataset.csv
      s3:
        endpoint: s3.amazonaws.com
        bucket: my-bucket
        key: datasets/data.csv
        accessKeySecret: { name: aws-credentials, key: accessKey }
        secretKeySecret: { name: aws-credentials, key: secretKey }
  • Outputs
    • path is a file or dir, dirs are tarred+gzipped by default
    • archive: none: {} uploads as is
    • optional: true doesn’t fail if the path doesn’t exist
outputs:
  artifacts:
    - name: raw-output
      path: /output
      archive:
        none: {}
    - name: maybe
      path: /tmp/optional-file.txt
      optional: true

Artifact repository

  • Default one is set in the workflow-controller-configmap (artifactRepository key)
data:
  artifactRepository: |
    s3:
      bucket: my-workflow-artifacts
      endpoint: s3.amazonaws.com
      region: us-west-2
      accessKeySecret:
        name: aws-credentials
        key: accessKey
      secretKeySecret:
        name: aws-credentials
        key: secretKey
  • Per workflow: spec.artifactRepositoryRef pointing to a ConfigMap and key
spec:
  artifactRepositoryRef:
    configMap: custom-artifact-repo-config
    key: artifactRepository
  • Supported: S3 (AWS, MinIO), GCS, Azure Blob, Artifactory, HDFS, OSS
    • MinIO: s3 with endpoint: minio.example.com:9000 and insecure: true
    • GCS: gcs with bucket, serviceAccountKeySecret
  • Quick start install already ships MinIO as the repository
  • keyFormat customizes the object path, e.g. {{workflow.name}}/{{pod.name}}

Volumes

  • Artifacts copy data through the repo; volumes share data directly

volumeClaimTemplates

  • PVC created with the workflow, deleted when it finishes
spec:
  volumeClaimTemplates:
    - metadata:
        name: workspace
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 1Gi
  templates:
    - name: writer
      container:
        image: alpine:latest
        command: [sh, -c]
        args: ["echo 'Shared data' > /workspace/data.txt"]
        volumeMounts:
          - name: workspace
            mountPath: /workspace
  • ReadWriteOnce + parallel steps on different nodes can get stuck, use ReadWriteMany or keep them sequential

Existing PVC

spec:
  volumes:
    - name: existing-storage
      persistentVolumeClaim:
        claimName: my-existing-pvc

emptyDir

  • Only shared between containers in the same pod, so it’s not a way to pass data between separate steps (each step is its own pod)

Remember