Skip to content

Commit

Permalink
Add Step and Sidecar Overrides to TaskRun API
Browse files Browse the repository at this point in the history
This commit adds TaskRunStepOverrides and TaskRunSidecarOverrides to TaskRun.Spec and
PipelineRun.Spec.PipelineTaskRunSpec, gated behind the "alpha" API flag.
This is part 1 of implementing TEP-0094: Configuring Resource Requirements at Runtime.
https://github.com/tektoncd/community/blob/main/teps/0094-configuring-resources-at-runtime.md
  • Loading branch information
lbernick authored and tekton-robot committed Feb 17, 2022
1 parent b6d21ed commit 9605e3e
Show file tree
Hide file tree
Showing 12 changed files with 658 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ Features currently in "alpha" are:
| [Windows Scripts](./tasks.md#windows-scripts) | [TEP-0057](https://github.com/tektoncd/community/blob/main/teps/0057-windows-support.md) | [v0.28.0](https://github.com/tektoncd/pipeline/releases/tag/v0.28.0) | |
| [Remote Tasks](./taskruns.md#remote-tasks) and [Remote Pipelines](./pipelineruns.md#remote-pipelines) | [TEP-0060](https://github.com/tektoncd/community/blob/main/teps/0060-remote-resolutiond.md) | | |
| [Debug](./debug.md) | [TEP-0042](https://github.com/tektoncd/community/blob/main/teps/0042-taskrun-breakpoint-on-failure.md) | [v0.26.0](https://github.com/tektoncd/pipeline/releases/tag/v0.26.0) | |
| [Step and Sidecar Overrides](./taskruns.md#overriding-task-steps-and-sidecars)| [TEP-0094](https://github.com/tektoncd/community/blob/main/teps/0094-specifying-resource-requirements-at-runtime.md) | | |

## Configuring High Availability

Expand Down
2 changes: 2 additions & 0 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ spec:
```

If used with this `Pipeline`, `build-task` will use the task specific `PodTemplate` (where `nodeSelector` has `disktype` equal to `ssd`).
`PipelineTaskRunSpec` may also contain `StepOverrides` and `SidecarOverrides`; see
[Overriding `Task` `Steps` and `Sidecars`](./taskruns.md#overriding-task-steps-and-sidecars) for more information.

### Specifying `Workspaces`

Expand Down
54 changes: 53 additions & 1 deletion docs/taskruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ weight: 300
- [Specifying a `Pod` template](#specifying-a-pod-template)
- [Specifying `Workspaces`](#specifying-workspaces)
- [Specifying `Sidecars`](#specifying-sidecars)
- [Overriding `Task` `Steps` and `Sidecars`](#overriding-task-steps-and-sidecars)
- [Specifying `LimitRange` values](#specifying-limitrange-values)
- [Configuring the failure timeout](#configuring-the-failure-timeout)
- [Specifying `ServiceAccount` credentials](#specifying-serviceaccount-credentials)
Expand Down Expand Up @@ -306,7 +307,8 @@ spec:
### Specifying `Resource` limits

Each Step in a Task can specify its resource requirements. See
[Defining `Steps`](tasks.md#defining-steps)
[Defining `Steps`](tasks.md#defining-steps). Resource requirements defined in Steps and Sidecars
may be overridden by a TaskRun's StepOverrides and SidecarOverrides.

### Specifying a `Pod` template

Expand Down Expand Up @@ -399,6 +401,56 @@ inside the `Pod`. Only the above command is affected. The `Pod's` description co
denotes a "Failed" status and the container statuses correctly denote their exit codes
and reasons.

### Overriding Task Steps and Sidecars

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**
**Warning: This feature is still under development and is not yet functional. Do not use it.**

A TaskRun can specify `StepOverrides` or `SidecarOverrides` to override Step or Sidecar
configuration specified in a Task.

For example, given the following Task definition:

```yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: image-build-task
spec:
steps:
- name: build
image: gcr.io/kaniko-project/executor:latest
sidecars:
- name: logging
image: my-logging-image
```

An example TaskRun definition could look like:

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: image-build-taskrun
spec:
taskRef:
name: image-build-task
stepOverrides:
- name: build
resources:
requests:
memory: 1Gi
sidecarOverrides:
- name: logging
resources:
requests:
cpu: 100m
limits:
cpu: 500m
```
`StepOverrides` and `SidecarOverrides` must include the `name` field and may include `resources`.
No other fields can be overridden.

### Specifying `LimitRange` values

In order to only consume the bare minimum amount of resources needed to execute one `Step` at a
Expand Down
122 changes: 120 additions & 2 deletions pkg/apis/pipeline/v1beta1/openapi_generated.go

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

8 changes: 5 additions & 3 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,11 @@ type PipelineTaskRun struct {
// 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"`
PipelineTaskName string `json:"pipelineTaskName,omitempty"`
TaskServiceAccountName string `json:"taskServiceAccountName,omitempty"`
TaskPodTemplate *PodTemplate `json:"taskPodTemplate,omitempty"`
StepOverrides []TaskRunStepOverride `json:"stepOverrides,omitempty"`
SidecarOverrides []TaskRunSidecarOverride `json:"sidecarOverrides,omitempty"`
}

// GetTaskRunSpec returns the task specific spec for a given
Expand Down
24 changes: 24 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipelinerun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (ps *PipelineRunSpec) Validate(ctx context.Context) (errs *apis.FieldError)
}
}

for idx, trs := range ps.TaskRunSpecs {
errs = errs.Also(validateTaskRunSpec(ctx, trs).ViaIndex(idx).ViaField("taskRunSpecs"))
}

return errs
}

Expand Down Expand Up @@ -188,3 +192,23 @@ func (ps *PipelineRunSpec) validatePipelineTimeout(timeout time.Duration, errorM
}
return errs
}

func validateTaskRunSpec(ctx context.Context, trs PipelineTaskRunSpec) (errs *apis.FieldError) {
cfg := config.FromContextOrDefaults(ctx)
if cfg.FeatureFlags.EnableAPIFields == config.AlphaAPIFields {
if trs.StepOverrides != nil {
errs = errs.Also(validateStepOverrides(trs.StepOverrides).ViaField("stepOverrides"))
}
if trs.SidecarOverrides != nil {
errs = errs.Also(validateSidecarOverrides(trs.SidecarOverrides).ViaField("sidecarOverrides"))
}
} else {
if trs.StepOverrides != nil {
errs = errs.Also(apis.ErrDisallowedFields("stepOverrides"))
}
if trs.SidecarOverrides != nil {
errs = errs.Also(apis.ErrDisallowedFields("sidecarOverrides"))
}
}
return errs
}
Loading

0 comments on commit 9605e3e

Please sign in to comment.