Argo Workflows: Input Parameters in a WorkflowTemplate

argo workflows input parameters template

2 min read | by Jordi Prats

Having a WorkflowTemplate with input parameters in Argo Workflows allows you to create reusable templates that can be customized at runtime. This is useful when you want to pass dynamic values to the workflow template when you submit it.

Following the example of the WorkflowTemplate that builds and pushes a Docker image using Kaniko, we are going to update it to use input parameters.

Here's how you can modify your WorkflowTemplate to use input parameters for --dockerfile, --context and --destination:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: build-and-push-image-with-inputs
spec:
  entrypoint: kaniko-build

  volumes:
    - name: kaniko-secret
      secret:
        secretName: dockerhub-registry
        items:
        - key: .dockerconfigjson
          path: config.json

  arguments:
    parameters:
      - name: git-repo-url
      - name: image-destination
      - name: dockerfile
        value: "Dockerfile"

  templates:
    - name: kaniko-build
      inputs:
        parameters:
          - name: git-repo-url
          - name: image-destination
          - name: dockerfile
      container:
        image: gcr.io/kaniko-project/executor:latest
        args:
          - --dockerfile={{inputs.parameters.dockerfile}}
          - --context={{inputs.parameters.git-repo-url}}
          - --destination={{inputs.parameters.image-destination}}
        volumeMounts:
        - name: kaniko-secret
          mountPath: "/kaniko/.docker"

Input parameters for this workflow:

  • git-repo-url and image-destination don't have default values, so it becomes mandatory to supply that parameter when you submit the workflow. If you don't, the workflow will fail with an error indicating that the required parameter is missing.
  • dockerfile: Has a default value, so we can override it in the Workflow submission if needed.

To create a Workflow from this template, you can set the parameters as follows:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: build-and-push-image-
spec:
  workflowTemplateRef:
    name: build-and-push-image-with-inputs
  arguments:
    parameters:
      - name: git-repo-url
        value: "git://github.com/jordiprats/flask-pet2cattle.git#refs/heads/master"
      - name: image-destination
        value: "jordiprats/ampa:kaniko"

This will use the provided values for git-repo-url and image-destination, while keeping the default value for dockerfile:

$ kubectl apply -f kaniko-template-input.yaml
workflowtemplate.argoproj.io/build-and-push-image-with-inputs created
$ kubectl create -f kaniko-template-input-instance.yaml ; kubectl get workflow -w
workflow.argoproj.io/build-and-push-image-hqnkn created
NAME                         STATUS   AGE   MESSAGE
build-and-push-image-hqnkn
build-and-push-image-hqnkn   Running   1s
build-and-push-image-hqnkn   Running   10s
build-and-push-image-hqnkn   Succeeded   49s

Posted on 28/10/2024