Skip to content

Commit 5fd22b5

Browse files
authored
Merge pull request #263 from adambkaplan/ship-build-runtime-class
SHIP-0040: Support RuntimeClass in Builds
2 parents 5cf5226 + 69b7a17 commit 5fd22b5

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

ships/0040-build-runtime-class.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<!--
2+
Copyright The Shipwright Contributors
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
---
8+
title: build-runtime-class
9+
authors:
10+
- "@adambkaplan"
11+
reviewers:
12+
- "@dorzel"
13+
- "@HeavyWombat"
14+
approvers:
15+
- "@qu1queee"
16+
- "@SaschaSchwarze0"
17+
creation-date: 2025-03-25
18+
last-updated: 2025-03-25
19+
status: provisional
20+
see-also:
21+
- "/ships/0039-build-scheduler-opts.md"
22+
replaces: []
23+
superseded-by: []
24+
---
25+
26+
# Build Runtime Class
27+
28+
## Release Signoff Checklist
29+
30+
- [ ] Enhancement is `implementable`
31+
- [ ] Design details are appropriately documented from clear requirements
32+
- [ ] Test plan is defined
33+
- [ ] Graduation criteria for dev preview, tech preview, GA
34+
- [ ] User-facing documentation is created in [docs](/docs/)
35+
36+
## Open Questions [optional]
37+
38+
- Should user namespaces also be in scope for this feature?
39+
_No, this should be considered separately. Feature is beta as of k8s v1.30_.
40+
41+
## Summary
42+
43+
Extend the `Build` and `BuildRun` APIs to let build pods select their [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/)
44+
for execution.
45+
46+
## Motivation
47+
48+
The `RuntimeClass` API lets Kubernetes clusters support multiple container runtime environments.
49+
This is most often encountered when using [Kata containers](https://katacontainers.io/), which adds
50+
hardware virtualization to the existing mechanisms for isolating containers.
51+
52+
### Goals
53+
54+
- Allow builds to run with alternative container runtimes, such as Kata containers.
55+
56+
### Non-Goals
57+
58+
- Automatic mechanisms for selecting the container runtime.
59+
- Network isolated builds.
60+
- Isolation with Kubernetes [user namespaces](https://kubernetes.io/docs/concepts/workloads/pods/user-namespaces/).
61+
62+
## Proposal
63+
64+
### User Stories
65+
66+
#### Kata Containers
67+
68+
As a developer building containers with Shipwright I want to specify that the build pod containers
69+
use Kata containers as their runtime so that I can isolate my builds with hardware virtualization.
70+
71+
### Implementation Notes
72+
73+
#### API Update
74+
75+
The `BuildSpec` API for Build and BuildRun will be updated to add the `runtimeClass` field:
76+
77+
```yaml
78+
spec:
79+
...
80+
runtimeClassName: kata # string
81+
```
82+
83+
This field will correspond to the [runtimeClassName](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#scheduling)
84+
field on Kubernetes pods.
85+
86+
#### Precedence Ordering and Value Merging
87+
88+
Values in `BuildRun` will override those in the referenced `Build` object (if present). This allows
89+
the `BuildRun` object to "inherit" values from a parent `Build` object.
90+
91+
#### Impact on Tekton TaskRun
92+
93+
Tekton supports tuning the pod of the `TaskRun` using the
94+
[podTemplate](https://tekton.dev/docs/pipelines/taskruns/#specifying-a-pod-template) field. When
95+
Shipwright creates the `TaskRun` for a build, the respective `runtimeClassName` can be passed
96+
through.
97+
98+
#### Command Line Enhancements
99+
100+
The `shp` CLI _may_ be enhanced to add flags that set the `runtimeClassName` for a `Build` and/or
101+
`BuildRun`. For example, `shp build run` can have the following new options:
102+
103+
- `--runtime-class=<value>`: this would set the respective `spec.runtimeClassName` value on the
104+
generated `BuildRun`.
105+
106+
### Test Plan
107+
108+
- Unit testing can verify that the generated `TaskRun` object for a build contains the desired pod
109+
template fields.
110+
- End to end testing may prove challenging, as KinD is not designed to support multiple container
111+
runtimes. Implementations like Kata Containers are designed for real clusters on cloud provider
112+
infrastructure.
113+
114+
115+
### Release Criteria
116+
117+
**Note:** *Section not required until targeted at a release.*
118+
119+
#### Removing a deprecated feature [if necessary]
120+
121+
Not applicable.
122+
123+
#### Upgrade Strategy [if necessary]
124+
125+
The `runtimeClassName` field will be optional and default to Golang empty values.
126+
On upgrade, these values will remain empty on existing `Build`/`BuildRun` objects.
127+
128+
### Risks and Mitigations
129+
130+
#### Pod Scheduling Collision
131+
132+
The `RuntimeClass` object (set and maintained by cluster admins/platform teams) also has options
133+
to set defaults for [pod scheduling](https://kubernetes.io/docs/concepts/containers/runtime-class/#scheduling),
134+
such as node selectors and tolerations. As of Kubernetes 1.32, this is a "beta" feature enabled
135+
on most Kubernetes distributions by default. These scheduler options are merged on pod admission;
136+
there is a risk that pods are rejected and builds fail due to colliding pod scheduler values.
137+
138+
In theory the controller for `BuildRuns` can anticipate this situation and fail the build quickly.
139+
However, other Kubernetes controllers do not appear to do this, and thus it may not be worthwhile
140+
to add this extra logic. Checking the `RuntimeClass` for every build also adds overhead to each
141+
reconcile loop, either by making kubernetes apiserver calls directly or adding an informer-based
142+
cache for `RuntimeClass` that provides little value.
143+
144+
## Drawbacks
145+
146+
This continues our leaking of Kubernetes pod APIs to Shipwright - see
147+
[SHIP-0039](https://github.com/shipwright-io/community/blob/main/ships/0039-build-scheduler-opts.md#drawbacks).
148+
Similar drawbacks also exist with respect to cluster admin control over pod scheduling.
149+
150+
## Alternatives
151+
152+
### Kubernetes User Namespaces
153+
154+
An initial draft of this proposal included Kubernetes
155+
[user namespaces](https://kubernetes.io/docs/concepts/workloads/pods/user-namespaces/) as part of
156+
the scope. This was removed because user namespaces are a beta feature in Kubernetes (as of v1.32),
157+
and did not reach the beta milestone until v1.30. Even with achievement of the beta milestone, the
158+
feature is still disabled by default in Kubernetes v1.32, making it challenging to test.
159+
160+
## Infrastructure Needed [optional]
161+
162+
No additional infrastructure anticipated.
163+
164+
165+
## Implementation History
166+
167+
- 2025-03-25: Created as `provisional`

0 commit comments

Comments
 (0)