-
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.
- Loading branch information
Showing
2 changed files
with
290 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,289 @@ | ||
--- | ||
status: proposed | ||
title: Add taskRunSpec template in PipelineRun | ||
creation-date: '2022-08-12' | ||
last-updated: '2022-08-12' | ||
authors: | ||
- '@yuzp1996' | ||
--- | ||
|
||
# TEP-0119: Add taskRunSpec template in PipelineRun | ||
|
||
<!-- toc --> | ||
- [Summary](#summary) | ||
- [Use Cases](#use-cases) | ||
- [Proposal](#proposal) | ||
- [Design Details](#design-details) | ||
- [Former implement](#former-implement) | ||
- [implement](#implement) | ||
- [Test Plan](#test-plan) | ||
<!-- /toc --> | ||
|
||
## Summary | ||
User is supported to configure specify specific taskrun spec when they create pipelinerun. However, users is not supported to specify spec for all taskrun. | ||
If you want to specify a common configuration for all taskrun they must specify them individually. | ||
|
||
This Tep is try to provide a convenient way that specify all taskrun spec 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 taskRunSpecTemplate to PipelineRun.Spec then we can specify the common configuration in taskRunSpecTemplate, and the configuration will apply to all the TasRun. | ||
|
||
```yaml | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: clone-build- | ||
spec: | ||
pipelineRef: | ||
name: pipeline | ||
taskRunSpecs: | ||
- pipelineTaskName: clone | ||
metadata: | ||
annotations: | ||
vault.hashicorp.com/agent-inject-secret-foo: "/path/to/foo" | ||
vault.hashicorp.com/role: role-name | ||
// Add the following filed that same as taskRunSpecs | ||
+ taskRunSpecTemplate: | ||
+ metadata: | ||
+ annotations: | ||
+ vault.hashicorp.com/agent-inject-secret-foo: "/path/to/foo" | ||
+ vault.hashicorp.com/role: role-name | ||
+ taskServiceAccountName: xxx | ||
+ stepOverrides: xxx | ||
+ .... | ||
``` | ||
## Design Details | ||
|
||
### previous implementation | ||
logic of TaskRunSpecTemplate will be like as TaskRunSpecs and the difference is that TaskRunSpecTemplate will apply to all taskrun while | ||
TaskRunSpecs will apply to one of the taskrun. | ||
|
||
Taskrun controller will be like that | ||
1. TaskRunSpecTemplate will apply to all taskrun | ||
2. TaskRunSpecs will apply to specify taskrun | ||
|
||
In this way the priority of taskrunSpecs will higher than TaskRunSpecTemplate | ||
|
||
|
||
Expand pipelinerun.Spec and add taskRunSpecTemplate | ||
|
||
|
||
```go | ||
// PipelineRunSpec defines the desired state of PipelineRun | ||
type PipelineRunSpec struct { | ||
// +optional | ||
PipelineRef *PipelineRef `json:"pipelineRef,omitempty"` | ||
// +optional | ||
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"` | ||
// Resources is a list of bindings specifying which actual instances of | ||
// PipelineResources to use for the resources the Pipeline has declared | ||
// it needs. | ||
// +listType=atomic | ||
Resources []PipelineResourceBinding `json:"resources,omitempty"` | ||
// Params is a list of parameter names and values. | ||
// +listType=atomic | ||
Params []Param `json:"params,omitempty"` | ||
// +optional | ||
ServiceAccountName string `json:"serviceAccountName,omitempty"` | ||
|
||
// Used for cancelling a pipelinerun (and maybe more later on) | ||
// +optional | ||
Status PipelineRunSpecStatus `json:"status,omitempty"` | ||
// Time after which the Pipeline times out. | ||
// Currently three keys are accepted in the map | ||
// pipeline, tasks and finally | ||
// with Timeouts.pipeline >= Timeouts.tasks + Timeouts.finally | ||
// +optional | ||
Timeouts *TimeoutFields `json:"timeouts,omitempty"` | ||
|
||
// Timeout Deprecated: use pipelineRunSpec.Timeouts.Pipeline instead | ||
// Time after which the Pipeline times out. Defaults to never. | ||
// Refer to Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration | ||
// +optional | ||
Timeout *metav1.Duration `json:"timeout,omitempty"` | ||
// PodTemplate holds pod specific configuration | ||
PodTemplate *PodTemplate `json:"podTemplate,omitempty"` | ||
// Workspaces holds a set of workspace bindings that must match names | ||
// with those declared in the pipeline. | ||
// +optional | ||
// +listType=atomic | ||
Workspaces []WorkspaceBinding `json:"workspaces,omitempty"` | ||
// TaskRunSpecs holds a set of runtime specs | ||
// +optional | ||
// +listType=atomic | ||
TaskRunSpecs []PipelineTaskRunSpec `json:"taskRunSpecs,omitempty"` | ||
} | ||
|
||
|
||
// PipelineTaskRunSpec can be used to configure specific | ||
// specs for a concrete Task | ||
type PipelineTaskRunSpec struct { | ||
PipelineTaskName string `json:"pipelineTaskName,omitempty"` | ||
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"` | ||
} | ||
|
||
|
||
// GetTaskRunSpec returns the task specific spec for a given | ||
// PipelineTask if configured, otherwise it returns the PipelineRun's default. | ||
func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSpec { | ||
s := PipelineTaskRunSpec{ | ||
PipelineTaskName: pipelineTaskName, | ||
TaskServiceAccountName: pr.Spec.ServiceAccountName, | ||
TaskPodTemplate: pr.Spec.PodTemplate, | ||
} | ||
for _, task := range pr.Spec.TaskRunSpecs { | ||
if task.PipelineTaskName == pipelineTaskName { | ||
if task.TaskPodTemplate != nil { | ||
s.TaskPodTemplate = task.TaskPodTemplate | ||
} | ||
if task.TaskServiceAccountName != "" { | ||
s.TaskServiceAccountName = task.TaskServiceAccountName | ||
} | ||
s.StepOverrides = task.StepOverrides | ||
s.SidecarOverrides = task.SidecarOverrides | ||
s.Metadata = task.Metadata | ||
s.ComputeResources = task.ComputeResources | ||
} | ||
} | ||
return s | ||
} | ||
``` | ||
|
||
### changes | ||
logic of TaskRunSpecTemplate will be like as TaskRunSpecs and the difference is that TaskRunSpecTemplate will apply to all taskrun while | ||
TaskRunSpecs will apply to one of the taskrun. | ||
|
||
Taskrun controller will be like that | ||
1. TaskRunSpecTemplate will apply to all taskrun | ||
2. TaskRunSpecs will apply to specify taskrun | ||
|
||
In this way the priority of taskrunSpecs will higher than TaskRunSpecTemplate | ||
|
||
|
||
Expand pipelinerun.Spec and add taskRunSpecTemplate | ||
|
||
```go | ||
// PipelineRunSpec defines the desired state of PipelineRun | ||
type PipelineRunSpec struct { | ||
// +optional | ||
PipelineRef *PipelineRef `json:"pipelineRef,omitempty"` | ||
// +optional | ||
PipelineSpec *PipelineSpec `json:"pipelineSpec,omitempty"` | ||
// Resources is a list of bindings specifying which actual instances of | ||
// PipelineResources to use for the resources the Pipeline has declared | ||
// it needs. | ||
// +listType=atomic | ||
Resources []PipelineResourceBinding `json:"resources,omitempty"` | ||
// Params is a list of parameter names and values. | ||
// +listType=atomic | ||
Params []Param `json:"params,omitempty"` | ||
// +optional | ||
ServiceAccountName string `json:"serviceAccountName,omitempty"` | ||
|
||
// Used for cancelling a pipelinerun (and maybe more later on) | ||
// +optional | ||
Status PipelineRunSpecStatus `json:"status,omitempty"` | ||
// Time after which the Pipeline times out. | ||
// Currently three keys are accepted in the map | ||
// pipeline, tasks and finally | ||
// with Timeouts.pipeline >= Timeouts.tasks + Timeouts.finally | ||
// +optional | ||
Timeouts *TimeoutFields `json:"timeouts,omitempty"` | ||
|
||
// Timeout Deprecated: use pipelineRunSpec.Timeouts.Pipeline instead | ||
// Time after which the Pipeline times out. Defaults to never. | ||
// Refer to Go's ParseDuration documentation for expected format: https://golang.org/pkg/time/#ParseDuration | ||
// +optional | ||
Timeout *metav1.Duration `json:"timeout,omitempty"` | ||
// PodTemplate holds pod specific configuration | ||
PodTemplate *PodTemplate `json:"podTemplate,omitempty"` | ||
// Workspaces holds a set of workspace bindings that must match names | ||
// with those declared in the pipeline. | ||
// +optional | ||
// +listType=atomic | ||
Workspaces []WorkspaceBinding `json:"workspaces,omitempty"` | ||
// TaskRunSpecs holds a set of runtime specs | ||
// +optional | ||
// +listType=atomic | ||
TaskRunSpecs []PipelineTaskRunSpec `json:"taskRunSpecs,omitempty"` | ||
// TaskRunSpecTemplate means template of taskrun | ||
+ // +optional | ||
+ TaskRunSpecTemplate PipelineTaskRunSpecTemplate `json:"taskRunSpecTemplate,omitempty"` | ||
} | ||
|
||
// PipelineTaskRunSpec can be used to configure specific | ||
// specs for a concrete Task | ||
type PipelineTaskRunSpec struct { | ||
PipelineTaskName string `json:"pipelineTaskName,omitempty"` | ||
+ PipelineTaskRunSpecTemplate | ||
} | ||
|
||
+ type PipelineTaskRunSpecTemplate 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"` | ||
+ } | ||
|
||
|
||
// GetTaskRunSpec returns the task specific spec for a given | ||
// PipelineTask if configured, otherwise it returns the PipelineRun's default. | ||
func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSpec { | ||
s := PipelineTaskRunSpec{ | ||
PipelineTaskName: pipelineTaskName, | ||
+ PipelineTaskRunSpecTemplate: PipelineTaskRunSpecTemplate{ | ||
+ TaskServiceAccountName: pr.Spec.ServiceAccountName, | ||
+ TaskPodTemplate: pr.Spec.PodTemplate, | ||
}, | ||
} | ||
|
||
+ // Add logic that apply pr.Spec.TaskRunSpecTemplate to s first. | ||
+ logic here .... | ||
|
||
for _, task := range pr.Spec.TaskRunSpecs { | ||
if task.PipelineTaskName == pipelineTaskName { | ||
if task.TaskPodTemplate != nil { | ||
s.TaskPodTemplate = task.TaskPodTemplate | ||
} | ||
if task.TaskServiceAccountName != "" { | ||
s.TaskServiceAccountName = task.TaskServiceAccountName | ||
} | ||
s.StepOverrides = task.StepOverrides | ||
s.SidecarOverrides = task.SidecarOverrides | ||
s.Metadata = task.Metadata | ||
s.ComputeResources = task.ComputeResources | ||
} | ||
} | ||
return s | ||
} | ||
|
||
|
||
``` | ||
|
||
|
||
### Test Plan | ||
I think we should add integration and e2e test not just unit tests! |
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