-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tep for adding taskruntemplate in pipelinerun
Tep aims to resolve setting common configration for all taskrun in pipelinerun. Signed-off-by: yuzhipeng <yuzp1996@qq.com>
- Loading branch information
Showing
2 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
--- | ||
status: proposed | ||
title: Add taskRun template in PipelineRun | ||
creation-date: '2022-08-12' | ||
last-updated: '2022-08-12' | ||
authors: | ||
- '@yuzp1996' | ||
--- | ||
|
||
# TEP-0119: Add taskRun template in PipelineRun | ||
|
||
<!-- toc --> | ||
- [Summary](#summary) | ||
- [Use Cases](#use-cases) | ||
- [Proposal](#proposal) | ||
- [Design Details](#design-details) | ||
- [taskRunTemplate](#implement) | ||
- [Test Plan](#test-plan) | ||
<!-- /toc --> | ||
|
||
## Summary | ||
It is now supported for users to specify spec for a specific taskRun when creating a pipelineRun, but it is not supported for users to set spec for all taskRun. | ||
|
||
If you want to specify common configurations for all taskRun, you must specify them individually. | ||
|
||
This Tep attempts to provide a convenient way to specify the run specification of all tasks in pipelineRun. | ||
|
||
### Use Cases | ||
Pipeline and Task User: | ||
|
||
I would like to use the same service account for all of my pipeline tasks except one. | ||
|
||
I want to specify compute resources that each TaskRun in my PipelineRun should run with, and don't want to have to specify them individually for each TaskRun. | ||
|
||
## Proposal | ||
Add filed taskRunTemplate to PipelineRun.Spec then users can specify common configuration in taskRunTemplate and the configuration will apply to all the TaskRun. | ||
|
||
If user specify taskRun spec in pipelineRun with TaskRunSpec then it will be the highest priority. | ||
|
||
For example you have a pipeline which contains three tasks clone、unit-test and image-build. Now you want to create pipelineRun which unit-test and image-build use | ||
same serviceAccount while clone use a different serviceAccount. | ||
```yaml | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
name: clone-test-build | ||
spec: | ||
tasks: | ||
- name: clone | ||
taskRef: | ||
name: git-clone | ||
workspaces: | ||
- name: output | ||
workspace: git-source | ||
- name: unit-test | ||
runAfter: | ||
- clone | ||
taskRef: | ||
name: junit | ||
- name: image-build | ||
runAfter: | ||
- unit-test | ||
taskRef: | ||
name: buildah | ||
|
||
``` | ||
|
||
In this case, when you create pipelineRun you need to specify serviceAccount for every task. | ||
```yaml | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: clone-test-build- | ||
spec: | ||
pipelineRef: | ||
name: clone-test-build | ||
taskRunSpecs: | ||
- pipelineTaskName: clone | ||
taskServiceAccountName: git | ||
- pipelineTaskName: unit-test | ||
taskServiceAccountName: build | ||
- pipelineTaskName: image-build | ||
taskServiceAccountName: build | ||
``` | ||
With the help of taskRunTemplate you will save a lot of work. | ||
```yaml | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: clone-test-build- | ||
spec: | ||
pipelineRef: | ||
name: clone-test-build | ||
taskRunSpecs: | ||
- pipelineTaskName: clone | ||
taskServiceAccountName: git | ||
taskRunSpecTemplate: | ||
taskServiceAccountName: build | ||
|
||
``` | ||
|
||
Not only serviceAccount, but also data like computeResources metadata that you can specify for all tasks instead of specify them individually. | ||
|
||
## Design Details | ||
### taskRunTemplate | ||
Add taskRunSpecTemplate to PipelineRun.Spec so that user can specify configuration. | ||
```go | ||
// Add struct PipelineTaskRunTemplate | ||
type PipelineTaskRunTemplate struct { | ||
TaskServiceAccountName string `json:"taskServiceAccountName,omitempty"` | ||
TaskPodTemplate *PodTemplate `json:"taskPodTemplate,omitempty"` | ||
// +listType=atomic | ||
StepOverrides []TaskRunStepOverride `json:"stepOverrides,omitempty"` | ||
// +listType=atomic | ||
SidecarOverrides []TaskRunSidecarOverride `json:"sidecarOverrides,omitempty"` | ||
|
||
// +optional | ||
Metadata *PipelineTaskMetadata `json:"metadata,omitempty"` | ||
|
||
// Compute resources to use for this TaskRun | ||
ComputeResources *corev1.ResourceRequirements `json:"computeResources,omitempty"` | ||
} | ||
|
||
// Reference PipelineTaskRunTemplate in PipelineRunSpec as filed TaskRunSpecTemplate | ||
type PipelineRunSpec struct { | ||
// +optional | ||
PipelineRef *PipelineRef `json:"pipelineRef,omitempty"` | ||
// +optional | ||
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"` | ||
..... | ||
// TaskRunTemplate represent template of taskrun | ||
+ // +optional | ||
+ TaskRunTemplate PipelineTaskRunTemplate `json:"taskRunTemplate,omitempty"` | ||
} | ||
|
||
``` | ||
|
||
Then, if you want to set a common configuration for all taskRun in pipelineRun, you can do so. | ||
```yaml | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: clone-test-build- | ||
spec: | ||
pipelineRef: | ||
name: clone-test-build | ||
taskRunSpecs: | ||
- pipelineTaskName: clone | ||
taskServiceAccountName: git | ||
taskRunTemplate: | ||
taskServiceAccountName: build | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject-secret-foo: "/path/to/foo" | ||
vault.hashicorp.com/role: role-name | ||
taskPodTemplate: | ||
nodeSelector: | ||
disktype: ssd | ||
computeResources: | ||
requests: | ||
cpu: 2 | ||
stepOverrides: | ||
- name: build | ||
resources: | ||
requests: | ||
memory: 1Gi | ||
sidecarOverrides: | ||
- name: logging | ||
resources: | ||
requests: | ||
cpu: 100m | ||
limits: | ||
cpu: 500m | ||
``` | ||
### Test Plan | ||
Unit tests are necessary, we can add some integration or e2e tests as appropriate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters