Search code examples
argo-workflows

Dynamically provide an image name for the container template


Is there a way to provide an image name for the container template dynamically based on its input parameters?

We have more than 30 different tasks each with its own image and that should be invoked identically in a workflow. The number may vary each run depending on the output of a previous task. So we don't want to or even can't just hardcode them inside workflow YAML.

An easy solution would be to provide the image field for the container depending on the input parameter and have the same template for each of these tasks. But looks like it's impossible. This workflow doesn't work:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-
spec:
  entrypoint: whalesay

  templates:
  - name: whalesay
    inputs:
      parameters:
        - name: image
          default: whalesay:latest
    container:
      image: "docker/{{image}}"
      command: [cowsay]
      args: ["hello world"]

Is there some workaround for this particular case?

Also is there a document somewhere describing in which fields one can use workflow variables? Documentation page says only:

Some fields in a workflow specification allow for variable references which are automatically substituted by Argo.


Solution

  • What you’re trying to do is definitely supported. Just change {{image}} to the fully qualified variable name {{inputs.parameters.image}}.

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    metadata:
      generateName: hello-world-
    spec:
      entrypoint: whalesay
      templates:
      - name: whalesay
        inputs:
          parameters:
            - name: image
              default: whalesay:latest
        container:
          image: "docker/{{inputs.parameters.image}}"
          command: [cowsay]
          args: ["hello world"]
    

    There is currently no documentation listing template-able fields. But there is an open issue for adding that documentation.