Skip to content

Commit

Permalink
Add Tep for adding taskruntemplate in pipelinerun
Browse files Browse the repository at this point in the history
Tep aims to resolve setting common configration for all taskrun
in pipelinerun.

Signed-off-by: yuzhipeng <yuzp1996@qq.com>
  • Loading branch information
yuzp1996 committed Aug 17, 2022
1 parent 28ac388 commit e676801
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
179 changes: 179 additions & 0 deletions teps/0119-add-taskrun-template-in-pipelinerun.md
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.
1 change: 1 addition & 0 deletions teps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,4 @@ This is the complete list of Tekton teps:
|[TEP-0114](0114-custom-tasks-beta.md) | Custom Tasks Beta | implementable | 2022-07-12 |
|[TEP-0116](0116-referencing-finally-task-results-in-pipeline-results.md) | Referencing Finally Task Results in Pipeline Results | implemented | 2022-08-11 |
|[TEP-0118](0118-matrix-with-explicit-combinations-of-parameters.md) | Matrix with Explicit Combinations of Parameters | implementable | 2022-08-08 |
|[TEP-0119](0119-add-taskrun-template-in-pipelinerun.md) | Add taskRun template in PipelineRun | proposed | 2022-08-12 |

0 comments on commit e676801

Please sign in to comment.