Skip to content

Commit

Permalink
feat(controller): Inline templates. Closes argoproj#5105 (argoproj#5749)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Aug 3, 2021
1 parent 7ef0f47 commit ec96415
Show file tree
Hide file tree
Showing 24 changed files with 966 additions and 559 deletions.
8 changes: 8 additions & 0 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,10 @@
"description": "Hooks hold the lifecycle hook which is invoked at lifecycle of task, irrespective of the success, failure, or error status of the primary task",
"type": "object"
},
"inline": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template",
"description": "Inline is the template. Template must be empty if this is declared (and vice-versa)."
},
"name": {
"description": "Name is the name of the target",
"type": "string"
Expand Down Expand Up @@ -6425,6 +6429,10 @@
"description": "Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step",
"type": "object"
},
"inline": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template",
"description": "Inline is the template. Template must be empty if this is declared (and vice-versa)."
},
"name": {
"description": "Name of the step",
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7259,6 +7259,10 @@
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.LifecycleHook"
}
},
"inline": {
"description": "Inline is the template. Template must be empty if this is declared (and vice-versa).",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
},
"name": {
"description": "Name is the name of the target",
"type": "string"
Expand Down Expand Up @@ -9851,6 +9855,10 @@
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.LifecycleHook"
}
},
"inline": {
"description": "Inline is the template. Template must be empty if this is declared (and vice-versa).",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Template"
},
"name": {
"description": "Name of the step",
"type": "string"
Expand Down
88 changes: 88 additions & 0 deletions docs/fields.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Templates

See [core concepts](core-concepts.md) for DAG, steps, container templates.

## Container Set Template

See [container set template](container-set-template.md).

## Inline Templates

![alpha](assets/alpha.svg)

> v3.2 and after
You can inline other templates within DAG and steps.

Examples:

* [DAG](examples/dag-inline-workflow.yaml)
* [Steps](examples/steps-inline-workflow.yaml)

!!! Warning
You can only inline once. Inlining a DAG within a DAG will not work.
18 changes: 18 additions & 0 deletions examples/dag-inline-clusterworkflowtemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: dag-inline
annotations:
workflows.argoproj.io/description: |
This examples demonstrates running a DAG with inline templates.
workflows.argoproj.io/version: ">= 3.2.0"
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: a
inline:
container:
image: argoproj/argosay:v2
13 changes: 13 additions & 0 deletions examples/dag-inline-cronworkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: dag-inline
annotations:
workflows.argoproj.io/description: |
This example demonstrates running cron workflow that has a DAG with inline templates.
workflows.argoproj.io/version: ">= 3.2.0"
spec:
schedule: "*/5 * * * *"
workflowSpec:
workflowTemplateRef:
name: dag-inline
22 changes: 22 additions & 0 deletions examples/dag-inline-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-inline-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
This example demonstrates running a DAG with inline templates.
workflows.argoproj.io/version: ">= 3.2.0"
workflows.argoproj.io/verify.py: |
assert status["phase"] == "Succeeded"
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: a
inline:
container:
image: argoproj/argosay:v2
18 changes: 18 additions & 0 deletions examples/dag-inline-workflowtemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: dag-inline
annotations:
workflows.argoproj.io/description: |
This example demonstrates running a DAG with inline templates.
workflows.argoproj.io/version: ">= 3.2.0"
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: a
inline:
container:
image: argoproj/argosay:v2
21 changes: 21 additions & 0 deletions examples/steps-inline-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-inline-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
This workflow demonstrates running a steps with inline templates.
workflows.argoproj.io/version: ">= 3.2.0"
workflows.argoproj.io/verify.py: |
assert status["phase"] == "Succeeded"
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: a
inline:
container:
image: argoproj/argosay:v2
Original file line number Diff line number Diff line change
Expand Up @@ -3387,6 +3387,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -9538,6 +9539,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down
2 changes: 2 additions & 0 deletions manifests/base/crds/full/argoproj.io_cronworkflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -9559,6 +9560,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down
5 changes: 5 additions & 0 deletions manifests/base/crds/full/argoproj.io_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3396,6 +3396,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -9547,6 +9548,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -18589,6 +18591,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -25694,6 +25697,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -31845,6 +31849,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down
1 change: 1 addition & 0 deletions manifests/base/crds/full/argoproj.io_workflowtasksets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down
2 changes: 2 additions & 0 deletions manifests/base/crds/full/argoproj.io_workflowtemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3386,6 +3386,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down Expand Up @@ -9537,6 +9538,7 @@ spec:
- template
type: object
type: object
inline: {}
name:
type: string
onExit:
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ nav:
- cluster-workflow-templates.md
- cron-workflows.md
- cron-backfill.md
- templates.md
- container-set-template.md
- template-defaults.md
- work-avoidance.md
- enhanced-depends-logic.md
- data-sourcing-and-transformation.md
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/workflow/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ type WorkflowSpecHolder interface {

// TemplateReferenceHolder is an object that holds a reference to other templates; e.g. WorkflowStep, DAGTask, and NodeStatus
type TemplateReferenceHolder interface {
GetTemplateName() string
// GetTemplate returns the template. This maybe nil. This is first precedence.
GetTemplate() *Template
// GetTemplateRef returns the template ref. This maybe nil. This is second precedence.
GetTemplateRef() *TemplateRef
// GetTemplateName returns the template name. This maybe empty. This is last precedence.
GetTemplateName() string
}

// SubmitOpts are workflow submission options
Expand Down
Loading

0 comments on commit ec96415

Please sign in to comment.