Skip to content

Commit

Permalink
Add taskRun template in v1 PipelineRun
Browse files Browse the repository at this point in the history
This commit adds the TaskRunTemplate in v1 PipelineRun Spec. It moves
the serviceAccountName and podTemplate from PipelineRun Spec. The rest
of the TaskRunTemplate fields are to be implemented after releasing v1.
  • Loading branch information
JeromeJu committed Sep 15, 2022
1 parent 6f41bff commit 93445b9
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 112 deletions.
38 changes: 38 additions & 0 deletions dev/docs/migrating-v1beta1-to-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ weight: 4000
- [Upgrading `PipelineRun.Timeout` to `PipelineRun.Timeouts`](#upgrading-pipelinerun.timeout-to-pipelinerun.timeouts)
- [Deprecating Resources from Task, TaskRun, Pipeline and PipelineRun](#deprecating-resources-from-task,-taskrun,-pipeline-and-pipelinerun)
- [Replacing `taskRef.bundle` and `pipelineRef.bundle` with Bundle Resolver](#replacing-taskRef.bundle-and-pipelineRef.bundle-with-bundle-resolver)
- [Adding `TaskRunTemplate` in `PipelineRun.Spec`](#adding-taskruntemplate-to-pipelinerun.spec)


This document describes the differences between `v1beta1` Tekton entities and their
Expand All @@ -32,6 +33,8 @@ In Tekton `v1`, the following fields have been changed:
| `taskrun.spec.resources` | removed from `TaskRun` |
| `pipeline.spec.resources` | removed from `Pipeline` |
| `pipelineRun.spec.resources` | removed from `PipelineRun` |
| `pipelineRun.spec.serviceAccountName` | [`pipelineRun.spec.taskRunTemplate.serviceAccountName`](#adding-taskruntemplate-to-pipelinerun.spec) |
| `pipelineRun.spec.podTemplate` | [`pipelineRun.spec.taskRunTemplate.podTemplate`](#adding-taskruntemplate-to-pipelinerun.spec) |

## Deprecating `resources` from Task, TaskRun, Pipeline and PipelineRun
`PipelineResources` are deprecated, and the `resources` fields of Task, TaskRun, Pipeline and PipelineRun has been removed. Please use `Tasks` instead. For more information, see [Replacing PipelineResources](https://github.com/tektoncd/pipeline/blob/main/docs/pipelineresources.md)
Expand Down Expand Up @@ -102,3 +105,38 @@ spec:
```

For more information, see [Remote resolution](https://github.com/tektoncd/community/blob/main/teps/0060-remote-resource-resolution.md).

## Adding TaskRunTemplate to PipelineRun.Spec
`ServiceAccountName` and `PodTemplate` are moved to `TaskRunTemplate` as `TaskRunTemplate.ServiceAccountName` and `TaskRunTemplate.PodTemplate` so that users can specify common configuration in `TaskRunTemplate` which will apply to all the TaskRuns.

```yaml
# Before in v1beta1:
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: template-pr
spec:
pipelineRef:
name: clone-test-build
serviceAccountName: build
podTemplate:
securityContext:
fsGroup: 65532
---
# After in v1:
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: template-pr
spec:
pipelineRef:
name: clone-test-build
taskRunSpecTemplate:
serviceAccountName: build
podTemplate:
securityContext:
fsGroup: 65532
```

*Currently, only `TaskRunTemplate.ServiceAccountName` and `TaskRunTemplate.PodTemplate` are implemented in v1 and the rest of the fields would be added after v1 release.
For more information, see [TEP-119](https://github.com/tektoncd/community/blob/main/teps/0119-add-taskrun-template-in-pipelinerun.md).
82 changes: 52 additions & 30 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,6 @@ PipelineSpec
</tr>
<tr>
<td>
<code>serviceAccountName</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>status</code><br/>
<em>
<a href="#tekton.dev/v1.PipelineRunSpecStatus">
Expand Down Expand Up @@ -531,15 +520,16 @@ with Timeouts.pipeline &gt;= Timeouts.tasks + Timeouts.finally</p>
</tr>
<tr>
<td>
<code>podTemplate</code><br/>
<code>taskRunTemplate</code><br/>
<em>
<a href="#tekton.dev/unversioned.Template">
Template
<a href="#tekton.dev/v1.PipelineTaskRunTemplate">
PipelineTaskRunTemplate
</a>
</em>
</td>
<td>
<p>PodTemplate holds pod specific configuration</p>
<em>(Optional)</em>
<p>TaskRunTemplate represent template of taskrun</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1773,17 +1763,6 @@ PipelineSpec
</tr>
<tr>
<td>
<code>serviceAccountName</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>status</code><br/>
<em>
<a href="#tekton.dev/v1.PipelineRunSpecStatus">
Expand Down Expand Up @@ -1815,15 +1794,16 @@ with Timeouts.pipeline &gt;= Timeouts.tasks + Timeouts.finally</p>
</tr>
<tr>
<td>
<code>podTemplate</code><br/>
<code>taskRunTemplate</code><br/>
<em>
<a href="#tekton.dev/unversioned.Template">
Template
<a href="#tekton.dev/v1.PipelineTaskRunTemplate">
PipelineTaskRunTemplate
</a>
</em>
</td>
<td>
<p>PodTemplate holds pod specific configuration</p>
<em>(Optional)</em>
<p>TaskRunTemplate represent template of taskrun</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -2548,6 +2528,48 @@ Kubernetes core/v1.ResourceRequirements
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.PipelineTaskRunTemplate">PipelineTaskRunTemplate
</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1.PipelineRunSpec">PipelineRunSpec</a>)
</p>
<div>
<p>PipelineTaskRunTemplate is used to specify run specifications for all Task in pipelinerun.</p>
</div>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>podTemplate</code><br/>
<em>
<a href="#tekton.dev/unversioned.Template">
Template
</a>
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>serviceAccountName</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.PipelineWorkspaceDeclaration">PipelineWorkspaceDeclaration
</h3>
<p>
Expand Down
42 changes: 32 additions & 10 deletions pkg/apis/pipeline/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/pipelinerun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (prs *PipelineRunSpec) SetDefaults(ctx context.Context) {
}

defaultSA := cfg.Defaults.DefaultServiceAccount
if prs.ServiceAccountName == "" && defaultSA != "" {
prs.ServiceAccountName = defaultSA
if prs.TaskRunTemplate.ServiceAccountName == "" && defaultSA != "" {
prs.TaskRunTemplate.ServiceAccountName = defaultSA
}

defaultPodTemplate := cfg.Defaults.DefaultPodTemplate
prs.PodTemplate = pod.MergePodTemplateWithDefault(prs.PodTemplate, defaultPodTemplate)
prs.TaskRunTemplate.PodTemplate = pod.MergePodTemplateWithDefault(prs.TaskRunTemplate.PodTemplate, defaultPodTemplate)

if prs.PipelineSpec != nil {
prs.PipelineSpec.SetDefaults(ctx)
Expand Down
Loading

0 comments on commit 93445b9

Please sign in to comment.