AFAIK there's no way to use a WorkflowTemplate and have the Workflow override the command and/or args provided by the template. If I'm wrong then let's shit this discussion to providing docs :)
Seeing as templates using templates is deprecated I can think of no way to achieve this simple task of having the template provide only the defaults while the workflow is still allowed to provide container specs.
In order to simplify lots of workflows we developed a CLI to run each task.
Lets say I have a CLI app like this:
my-cli plugins my-plugin start --name --from=X --to=X --force
my-cli plugins my-plugin stop --name
my-cli plugins my-plugin status --all --none --any --some
my-cli plugins my-plugin version --minor --major --patch --up --down --set=X
and this template:
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: cluster-workflow-cli-templates
spec:
arguments:
parameters:
- name: command
value: --help
templates:
- name: plugin-cli-template
inputs:
parameters:
- name: commands
container:
image: plugin:latest
args: [{{`"{{inputs.parameters.command}}"`}}]
command: [my-cli plugins my-plugin]
This is nice if I didn't have a nested API or too many CLI args, but when it gets bloated I'm forced to create a different unique template for every command i have in my CLI and set the arguments accordingly, repeating the volumes and image data over and over which defeats the purpose of a tempalte.
Won't it be nice if a workflow could inherit from a template and override the args or even the command so that workflow will have more control over what's executed while still inheriting volumes, mounts, image and all the repeating data i'm glad i have a template for?
Allow using templateRef with command and/or args as overrides.
Message from the maintainers:
If you wish to see this enhancement implemented please add a 馃憤 reaction to this issue! We often sort issues this way to know what to prioritize.
@dtaniwaki or @sarabala1979 do you want to own this please?
yes, I will update the comments
In v2.8
you can use step template to refer to the Workflowtemplate and pass the parameters
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
steps:
- - name: call-whalesay-template
templateRef:
name: workflow-template-whalesay-template
template: whalesay-template
arguments:
parameters:
- name: message
value: "hello world client"
WorkflowTemplate:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-whalesay-template
spec:
entrypoint: whalesay-template
templates:
- name: whalesay-template
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
Master : (It will be released in v2.9)
you can refer the Workflow-template in as workflow spec using WorkflowTemplateRef. you pass the glopal parameters to WorkflowTemplate
Workflow:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
entrypoint: whalesay-template
arguments:
parameters:
- name: message
value: "hello world client"
workflowTemplateRef:
name: workflow-template-whalesay-template
WorkflowTemplate:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-whalesay-template
spec:
entrypoint: whalesay-template
templates:
- name: whalesay-template
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{workflow.parameters.message}}"]
assuming i want to be able to pass multiple unknown cli args to the container's command from a workflow that uses a workflow-template, is that possible?
WorkflowTemplate:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-awscli-template
spec:
entrypoint: awscli-template
templates:
- name: awscli-template
inputs:
parameters:
- name: cmd
container:
image: awscli:latest
command: [aws]
args: ["{{workflow.parameters.cmd}}"]
and i want to use this single template to execute any workflow that has aws as the base command but with different args each time depending on the workflow itself (not the template). The above example will not work because args will only have a single cmd argument, i don't know of a way to dynamically add more when using a template.
I want this to be a workflow: (example of using the above template, "containing" all secrets, env-vars and volumes, for running an s3 list sub-command with its own args.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-awscli-
spec:
entrypoint: awscli-template
container: # how it would've been in a regular workflow (without a template ref)
args: [s3, list, --help]
workflowTemplateRef:
name: workflow-template-awscli-template
# args and command can also be here to extend the template ref locally
I tried below example with awscli somewhat it didn't work might aws cli parsing args might be different. But I tried with Linux it works. try with your container and let me know
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-awscli-template
spec:
entrypoint: awscli-template
templates:
- name: awscli-template
container:
image: alpine:latest
command: [sh, -c]
args: ['{{workflow.parameters.cmd}}']
workflow
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-awscli-
spec:
entrypoint: awscli-template
arguments:
parameters:
- name: cmd
value: "ls -lrth a*"
workflowTemplateRef:
name: workflow-template-awscli-template
you can pass dynamically args from cli also
argo submit wf.yaml -p cmd="ls -l b* "
it can only work if your cli is accepting a single string arg which contains multiple instructions in it, such as sh -c. that's exactly my problem, it doesn't seem possible to pass it multiple (a list of) args and this feature will help us greatly to organize our workflows and provide a more dynamic approach to templates.
Thanks for your clarification. Here solution which will work for your scenario.
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-awscli-template
spec:
entrypoint: awscli-template
templates:
- name: awscli-template
podSpecPatch: '{"containers":[{"name":"main", "args":[{{workflow.parameters.cmd}}]}]}'
container:
image: amazon/aws-cli:latest
command: [aws]
args: ["{{workflow.parameters.cmd}}"]
Workflow:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
arguments:
parameters:
- name: cmd
value: '"s3", "ls", "help"'
workflowTemplateRef:
name: workflow-template-awscli-template
i see.. that could do the trick! i'll test it and report back..
btw, i'll happily help improve the docs if you simply point me in the right direction. argo is a great tools with amazing potential for grow, but the docs are very scattered the confusing and it's hard to find all these very cool and helpful features :)
one followup question, why is podSpecPatch a string and not a map?
It is basically JSON/YAML string and it will patch to POD spec at runtime. Here a few different examples.
https://github.com/argoproj/argo/blob/master/examples/pod-spec-from-previous-step.yaml
https://github.com/argoproj/argo/blob/master/examples/pod-spec-patch-wf-tmpl.yaml
https://github.com/argoproj/argo/blob/master/examples/pod-spec-patch.yaml
https://github.com/argoproj/argo/blob/master/examples/pod-spec-yaml-patch.yaml
thanks, it did the trick..
i assume it isn't documented anywhere other then in examples.. do you want me to help with the docs? is there any work being done on that?
Thanks for confirming. Please go-ahead to create PR for this.
Most helpful comment
it can only work if your cli is accepting a single string arg which contains multiple instructions in it, such as
sh -c. that's exactly my problem, it doesn't seem possible to pass it multiple (a list of) args and this feature will help us greatly to organize our workflows and provide a more dynamic approach to templates.