-
Notifications
You must be signed in to change notification settings - Fork 17
SHIP-0040: Support RuntimeClass in Builds #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adambkaplan
wants to merge
2
commits into
shipwright-io:main
Choose a base branch
from
adambkaplan:ship-build-runtime-class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,167 @@ | ||
<!-- | ||
Copyright The Shipwright Contributors | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
--- | ||
title: build-runtime-class | ||
authors: | ||
- "@adambkaplan" | ||
reviewers: | ||
- "@dorzel" | ||
- "@HeavyWombat" | ||
approvers: | ||
- "@qu1queee" | ||
- "@SaschaSchwarze0" | ||
creation-date: 2025-03-25 | ||
last-updated: 2025-03-25 | ||
status: provisional | ||
see-also: | ||
- "/ships/0039-build-scheduler-opts.md" | ||
replaces: [] | ||
superseded-by: [] | ||
--- | ||
|
||
# Build Runtime Class | ||
|
||
## Release Signoff Checklist | ||
|
||
- [ ] Enhancement is `implementable` | ||
- [ ] Design details are appropriately documented from clear requirements | ||
- [ ] Test plan is defined | ||
- [ ] Graduation criteria for dev preview, tech preview, GA | ||
- [ ] User-facing documentation is created in [docs](/docs/) | ||
|
||
## Open Questions [optional] | ||
|
||
- Should user namespaces also be in scope for this feature? | ||
_No, this should be considered separately. Feature is beta as of k8s v1.30_. | ||
|
||
## Summary | ||
|
||
Extend the `Build` and `BuildRun` APIs to let build pods select their [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) | ||
for execution. | ||
|
||
## Motivation | ||
|
||
The `RuntimeClass` API lets Kubernetes clusters support multiple container runtime environments. | ||
This is most often encountered when using [Kata containers](https://katacontainers.io/), which adds | ||
hardware virtualization to the existing mechanisms for isolating containers. | ||
|
||
### Goals | ||
|
||
- Allow builds to run with alternative container runtimes, such as Kata containers. | ||
|
||
### Non-Goals | ||
|
||
- Automatic mechanisms for selecting the container runtime. | ||
- Network isolated builds. | ||
- Isolation with Kubernetes [user namespaces](https://kubernetes.io/docs/concepts/workloads/pods/user-namespaces/). | ||
|
||
## Proposal | ||
|
||
### User Stories | ||
|
||
#### Kata Containers | ||
|
||
As a developer building containers with Shipwright I want to specify that the build pod containers | ||
use Kata containers as their runtime so that I can isolate my builds with hardware virtualization. | ||
|
||
### Implementation Notes | ||
|
||
#### API Update | ||
|
||
The `BuildSpec` API for Build and BuildRun will be updated to add the `runtimeClass` field: | ||
|
||
```yaml | ||
spec: | ||
... | ||
runtimeClassName: kata # string | ||
``` | ||
|
||
This field will correspond to the [runtimeClassName](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling) | ||
field on Kubernetes pods. | ||
|
||
#### Precedence Ordering and Value Merging | ||
|
||
Values in `BuildRun` will override those in the referenced `Build` object (if present). This allows | ||
the `BuildRun` object to "inherit" values from a parent `Build` object. | ||
|
||
#### Impact on Tekton TaskRun | ||
|
||
Tekton supports tuning the pod of the `TaskRun` using the | ||
[podTemplate](https://tekton.dev/docs/pipelines/taskruns/#specifying-a-pod-template) field. When | ||
Shipwright creates the `TaskRun` for a build, the respective `runtimeClassName` can be passed | ||
through. | ||
|
||
#### Command Line Enhancements | ||
|
||
The `shp` CLI _may_ be enhanced to add flags that set the `runtimeClassName` for a `Build` and/or | ||
`BuildRun`. For example, `shp build run` can have the following new options: | ||
|
||
- `--runtime-class=<value>`: this would set the respective `spec.runtimeClassName` value on the | ||
generated `BuildRun`. | ||
|
||
### Test Plan | ||
|
||
- Unit testing can verify that the generated `TaskRun` object for a build contains the desired pod | ||
template fields. | ||
- End to end testing may prove challenging, as KinD is not designed to support multiple container | ||
runtimes. Implementations like Kata Containers are designed for real clusters on cloud provider | ||
infrastructure. | ||
|
||
|
||
### Release Criteria | ||
|
||
**Note:** *Section not required until targeted at a release.* | ||
|
||
#### Removing a deprecated feature [if necessary] | ||
|
||
Not applicable. | ||
|
||
#### Upgrade Strategy [if necessary] | ||
|
||
The `runtimeClassName` field will be optional and default to Golang empty values. | ||
On upgrade, these values will remain empty on existing `Build`/`BuildRun` objects. | ||
|
||
### Risks and Mitigations | ||
|
||
#### Pod Scheduling Collision | ||
|
||
The `RuntimeClass` object (set and maintained by cluster admins/platform teams) also has options | ||
to set defaults for [pod scheduling](https://kubernetes.io/docs/concepts/containers/runtime-class/#scheduling), | ||
such as node selectors and tolerations. As of Kubernetes 1.32, this is a "beta" feature enabled | ||
on most Kubernetes distributions by default. These scheduler options are merged on pod admission; | ||
there is a risk that pods are rejected and builds fail due to colliding pod scheduler values. | ||
|
||
In theory the controller for `BuildRuns` can anticipate this situation and fail the build quickly. | ||
However, other Kubernetes controllers do not appear to do this, and thus it may not be worthwhile | ||
to add this extra logic. Checking the `RuntimeClass` for every build also adds overhead to each | ||
reconcile loop, either by making kubernetes apiserver calls directly or adding an informer-based | ||
cache for `RuntimeClass` that provides little value. | ||
|
||
## Drawbacks | ||
|
||
This continues our leaking of Kubernetes pod APIs to Shipwright - see | ||
[SHIP-0039](https://github.com/shipwright-io/community/blob/main/ships/0039-build-scheduler-opts.md#drawbacks). | ||
Similar drawbacks also exist with respect to cluster admin control over pod scheduling. | ||
|
||
## Alternatives | ||
|
||
### Kubernetes User Namespaces | ||
|
||
An initial draft of this proposal included Kubernetes | ||
[user namespaces](https://kubernetes.io/docs/concepts/workloads/pods/user-namespaces/) as part of | ||
the scope. This was removed because user namespaces are a beta feature in Kubernetes (as of v1.32), | ||
and did not reach the beta milestone until v1.30. Even with achievement of the beta milestone, the | ||
feature is still disabled by default in Kubernetes v1.32, making it challenging to test. | ||
|
||
## Infrastructure Needed [optional] | ||
|
||
No additional infrastructure anticipated. | ||
|
||
|
||
## Implementation History | ||
|
||
- 2025-03-25: Created as `provisional` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a Kubernetes Beta feature which is disabled by default afaik. Anyway, I would be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to move user namespaces out of scope. It is a bit odd that it is "beta" but still off by default. I guess not all CRI runtimes support it (and something like KinD may not be able to ever support it?).