Skip to content

Commit 97e3d2b

Browse files
ScrapCodestekton-robot
authored andcommitted
TEP-0061, Added documentation for embedding spec in custom-task
1 parent ab48625 commit 97e3d2b

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

docs/pipelines.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,31 @@ If the `taskRef` specifies a name, the custom task controller should look up the
11921192
If the `taskRef` does not specify a name, the custom task controller might support
11931193
some default behavior for executing unnamed tasks.
11941194

1195+
### Specifying a Custom Task Spec in-line (or embedded)
1196+
1197+
```yaml
1198+
spec:
1199+
tasks:
1200+
- name: run-custom-task
1201+
taskSpec:
1202+
apiVersion: example.dev/v1alpha1
1203+
kind: Example
1204+
spec:
1205+
field1: value1
1206+
field2: value2
1207+
```
1208+
1209+
If the custom task controller supports the in-line or embedded task spec, this will create a `Run` of a custom task of
1210+
type `Example` in the `example.dev` API group with the version `v1alpha1`.
1211+
1212+
If the `taskSpec` is not supported, the custom task controller should produce proper validation errors.
1213+
1214+
Please take a look at the
1215+
[developer guide for custom controllers supporting `taskSpec`.](runs.md#developer-guide-for-custom-controllers-supporting-spec)
1216+
1217+
`taskSpec` support for `pipelineRun` was designed and discussed in
1218+
[TEP-0061](https://github.com/tektoncd/community/blob/main/teps/0061-allow-custom-task-to-be-embedded-in-pipeline.md)
1219+
11951220
### Specifying parameters
11961221

11971222
If a custom task supports [`parameters`](tasks.md#parameters), you can use the

docs/runs.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ A `Run` definition supports the following fields:
4747
- [`metadata`][kubernetes-overview] - Specifies the metadata that uniquely identifies the
4848
`Run`, such as a `name`.
4949
- [`spec`][kubernetes-overview] - Specifies the configuration for the `Run`.
50-
- [`ref`](#specifying-the-target-custom-task) - Specifies the type and
50+
- [`ref`](#1-specifying-the-target-custom-task-with-ref) - Specifies the type and
5151
(optionally) name of the custom task type to execute.
52+
- [`spec`](#2-specifying-the-target-custom-task-by-embedding-its-spec) - Embed the custom task resource spec
53+
directly in a `Run`.
5254
- Optional:
5355
- [`params`](#specifying-parameters) - Specifies the desired execution
5456
parameters for the custom task.
@@ -64,6 +66,19 @@ A `Run` definition supports the following fields:
6466

6567
### Specifying the target Custom Task
6668

69+
A custom task resource's `Spec` may be directly embedded in the `Run` or it may
70+
be referred to by a `Ref`. But, not both at the same time.
71+
72+
1. [Specifying the target Custom Task with ref](#1-specifying-the-target-custom-task-with-ref)
73+
Referring a custom task (i.e. `Ref` ) promotes reuse of custom task definitions.
74+
75+
2. [Specifying the target Custom Task by embedding its spec](#2-specifying-the-target-custom-task-by-embedding-its-spec)
76+
Embedding a custom task (i.e. `Spec` ) helps in avoiding name collisions with other users within the same namespace.
77+
Additionally, in a pipeline with multiple embedded custom tasks, the details of entire pipeline can be fetched in a
78+
single API request.
79+
80+
### 1. Specifying the target Custom Task with ref
81+
6782
To specify the custom task type you want to execute in your `Run`, use the
6883
`ref` field as shown below:
6984

@@ -99,6 +114,45 @@ In either case, if the named resource cannot be found, or if unnamed tasks are
99114
not supported, the custom task controller should update the `Run`'s status to
100115
indicate the error.
101116

117+
### 2. Specifying the target Custom Task by embedding its spec
118+
119+
To specify the custom task spec, it can be embedded directly into a
120+
`Run`'s spec as shown below:
121+
122+
```yaml
123+
apiVersion: tekton.dev/v1alpha1
124+
kind: Run
125+
metadata:
126+
name: embedded-run
127+
spec:
128+
spec:
129+
apiVersion: example.dev/v1alpha1
130+
kind: Example
131+
spec:
132+
field1: value1
133+
field2: value2
134+
```
135+
136+
This initiates the execution of a `Run` of a custom task of type `Example`, in
137+
the `example.dev` API group, with the version `v1alpha1`.
138+
139+
#### Developer guide for custom controllers supporting `spec`.
140+
141+
1. A custom controller may or may not support a `Spec`. In cases where it is
142+
not supported the custom controller should respond with proper validation error.
143+
144+
2. Validation of the fields of the custom task is delegated to the custom task controller. It is recommended to
145+
implement validations as asynchronous
146+
(i.e. at reconcile time), rather than part of the webhook. Using a webhook for validation is problematic because, it
147+
is not possible to filter custom task resource objects before validation step, as a result each custom task resource
148+
has to undergo validation by all the installed custom task controllers.
149+
150+
3. A custom task may have an empty spec, but cannot have an empty
151+
`ApiVersion` and `Kind`. Custom task controllers should handle
152+
an empty spec, either with a default behaviour, in a case no default
153+
behaviour is supported then, appropriate validation error should be
154+
updated to the `Run`'s status.
155+
102156
### Specifying `Parameters`
103157

104158
If a custom task supports [`parameters`](tasks.md#parameters), you can use the

pkg/reconciler/pipelinerun/pipelinerun_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ func TestReconcile_CustomTask(t *testing.T) {
542542
APIVersion: "example.dev/v0",
543543
Kind: "Example",
544544
},
545+
Metadata: v1beta1.PipelineTaskMetadata{Labels: map[string]string{"test-label": "test"}},
545546
Spec: runtime.RawExtension{
546547
Raw: []byte(`{"field1":123,"field2":"value"}`),
547548
},
@@ -578,6 +579,7 @@ func TestReconcile_CustomTask(t *testing.T) {
578579
APIVersion: "example.dev/v0",
579580
Kind: "Example",
580581
},
582+
Metadata: v1beta1.PipelineTaskMetadata{Labels: map[string]string{"test-label": "test"}},
581583
Spec: runtime.RawExtension{
582584
Raw: []byte(`{"field1":123,"field2":"value"}`),
583585
},

0 commit comments

Comments
 (0)