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:
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