v2.4 and after
WorkflowTemplates
are definitions of Workflows
that live in your cluster. This allows you to create a library of
frequently-used templates and reuse them either by submitting them directly (v2.7 and after) or by referencing them from
your Workflows
.
The terms WorkflowTemplate
and template
have created an unfortunate naming collision and have created some confusion
in the past. However, a quick description should clarify each and their differences.
-
A
template
(lower-case) is a task within aWorkflow
or (confusingly) aWorkflowTemplate
under the fieldtemplates
. Whenever you define aWorkflow
, you must define at least one (but usually more than one)template
to run. Thistemplate
can be of typecontainer
,script
,dag
,steps
,resource
, orsuspend
and can be referenced by anentrypoint
or by otherdag
, andstep
templates.Here is an example of a
Workflow
with twotemplates
:apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: steps- spec: entrypoint: hello # We reference our first "template" here templates: - name: hello # The first "template" in this Workflow, it is referenced by "entrypoint" steps: # The type of this "template" is "steps" - - name: hello template: whalesay # We reference our second "template" here arguments: parameters: [{name: message, value: "hello1"}] - name: whalesay # The second "template" in this Workflow, it is referenced by "hello" inputs: parameters: - name: message container: # The type of this "template" is "container" image: docker/whalesay command: [cowsay] args: ["{{inputs.parameters.message}}"]```
-
A
WorkflowTemplate
is a definition of aWorkflow
that lives in your cluster. Since it is a definition of aWorkflow
it also containstemplates
. Thesetemplates
can be referenced from within theWorkflowTemplate
and from otherWorkflows
andWorkflowTemplates
on your cluster. To see how, please see Referencing OtherWorkflowTemplates
.
v2.7 and after
WorkflowTemplates
in v2.7 and after are full Workflow
definitions. You can take any existing Workflow
you may have
and convert it to a WorkflowTemplate
by substituting kind: Workflow
to kind: WorkflowTemplate
.
v2.4 – 2.6
WorkflowTemplates
in v2.4 - v2.6 are only partial Workflow
definitions and only support the templates
and
arguments
field.
This would not be a valid WorkflowTemplate
in v2.4 - v2.6 (notice entrypoint
field):
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-submittable
spec:
entrypoint: whalesay-template # Fields other than "arguments" and "templates" not supported in v2.4 - v2.6
arguments:
parameters:
- name: message
value: hello world
templates:
- name: whalesay-template
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
However, this would be a valid WorkflowTemplate
:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: workflow-template-submittable
spec:
arguments:
parameters:
- name: message
value: hello world
templates:
- name: whalesay-template
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
You can reference templates
from another WorkflowTemplates
(see the difference between the two) using a templateRef
field.
Just as how you reference other templates
within the same Workflow
, you should do so from a steps
or dag
template.
Here is an example from a steps
template:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
steps: # You should only reference external "templates" in a "steps" or "dag" "template".
- - name: call-whalesay-template
templateRef: # You can reference a "template" from another "WorkflowTemplate" using this field
name: workflow-template-1 # This is the name of the "WorkflowTemplate" CRD that contains the "template" you want
template: whalesay-template # This is the name of the "template" you want to reference
arguments: # You can pass in arguments as normal
parameters:
- name: message
value: "hello world"
You can also do so similarly with a dag
template:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
dag:
tasks:
- name: call-whalesay-template
templateRef:
name: workflow-template-1
template: whalesay-template
arguments:
parameters:
- name: message
value: "hello world"
You should never reference another template directly on a template
object (outside of a steps
or dag
template).
This includes both using template
and templateRef
.
This behavior is deprecated, no longer supported, and will be removed in a future version.
Here is an example of a deprecated reference that should not be used:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-hello-world-
spec:
entrypoint: whalesay
templates:
- name: whalesay
template: # You should NEVER use "template" here. Use it under a "steps" or "dag" template (see above).
templateRef: # You should NEVER use "templateRef" here. Use it under a "steps" or "dag" template (see above).
name: workflow-template-1
template: whalesay-template
arguments: # Arguments here are ignored. Use them under a "steps" or "dag" template (see above).
parameters:
- name: message
value: "hello world"
The reasoning for deprecating this behavior is that a template
is a "definition": it defines inputs and things to be
done once instantiated. With this deprecated behavior, the same template object is allowed to be an "instantiator":
to pass in "live" arguments and reference other templates (those other templates may be "definitions" or "instantiators").
This behavior has been problematic and dangerous. It causes confusion and has design inconsistencies.
You can create some example templates as follows:
argo template create https://raw.githubusercontent.com/argoproj/argo/master/examples/workflow-template/templates.yaml
The submit a workflow using one of those templates:
argo submit https://raw.githubusercontent.com/argoproj/argo/master/examples/workflow-template/hello-world.yam
Using kubectl apply -f
and kubectl get wftmpl
WorkflowTemplate
resources can be managed with GitOps by using Argo CD
WorkflowTemplate
resources can also be managed by the UI