Skip to content

Commit 1cb07da

Browse files
committed
RFC to create a lifecycle crd
Signed-off-by: Tom Kennedy <[email protected]>
1 parent e1722c0 commit 1cb07da

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

rfcs/0000-lifecycle-crd.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
`[Readable](https://github.com/your-name-or-org/kpack/blob/<pr-branch-name>/rfcs/0000-<my-feature>.md)`
2+
3+
**Problem:**
4+
5+
The CNB lifecycle is provided to kpack as in image reference in a configMap similar to how the completion and prepare
6+
images are passed to the kpack controller. This means that every builder will always use the same exact lifecycle, with
7+
no ability to specify an alternate one that may support different buildpack api or platform api versions. Due to kpack
8+
support of windows, a custom lifecycle image with specific layers for the linux and windows binaries is required
9+
(with a label specifying the layer diff id for each os). Because of this, a cve present in the lifecycle that has been
10+
patched upstream, requires any user to build the kpack specific lifecycle image themselves if the kpack provided one
11+
has not been bumped.
12+
13+
As we [move to deprecate windows](https://github.com/buildpacks-community/kpack/discussions/1366), there is an opportunity for us to utilize
14+
the upstream lifecycle image shipped by CNB, but switching to that image without changing the interface for providing the
15+
lifecycle to kpack may open the door to incompatibilities if the wrong image is used on a particular kpack version.
16+
17+
**Outcome:**
18+
19+
Users will be able to create a CR that references a lifecycle image. The file structure in the image must match
20+
that of the [CNB Lifecycle image](https://hub.docker.com/r/buildpacksio/lifecycle/tags).
21+
22+
```
23+
.
24+
└── cnb/
25+
└── lifecycle/
26+
├── analyzer
27+
├── builder
28+
├── detector
29+
├── exporter
30+
├── launcher
31+
├── lifecycle.toml
32+
└── restorer
33+
```
34+
35+
They will be able to use this lifecycle CR in any builder. A lifecycle will be shipped out of the box in kpack and
36+
users will not be required to provide a lifecycle reference in the builder if they do not wish to override the default.
37+
Users should see no difference in functionality compared to the existing kpack lifecycle if they do not choose to
38+
provide their own lifecycle CR.
39+
40+
**Actions to take:**
41+
42+
A new ClusterLifecycle CRD will be created. It will be very similar in structure to the ClusterStack Resource.
43+
One open question is whether we should follow the Clusterstack model and keep this resource strictly cluster scoped or
44+
follow the ClusterBuildpack pattern and provide a namespaced scoped version of the CRD.
45+
46+
This is an example instance of the proposed CRD:
47+
```yaml
48+
apiVersion: kpack.io/v1alpha2
49+
kind: ClusterLifecycle
50+
metadata:
51+
name: sample-cluster-lifecycle
52+
spec:
53+
serviceAccountRef:
54+
name: sample-sa
55+
namespace: sample-namespace
56+
image: buildpacksio/lifecycle@sha256:f4ce143ea6bbc6b5be5f4d151aba8214324adb93bbd7e3b1f43cd134ad450bf7
57+
```
58+
59+
If we were to create a namespaced version of this CRD it would look like this.
60+
Similar to Buildpack CRs, ClusterBuilders will not be able to use the namespaced CR:
61+
```yaml
62+
apiVersion: kpack.io/v1alpha2
63+
kind: Lifecycle
64+
metadata:
65+
name: sample-cluster-lifecycle
66+
namespace: test
67+
spec:
68+
serviceAccountName: sample-sa
69+
image: buildpacksio/lifecycle@sha256:f4ce143ea6bbc6b5be5f4d151aba8214324adb93bbd7e3b1f43cd134ad450bf7
70+
```
71+
72+
The existing lifecycle reconciler can be updated to reconcile this new CRD instead of ConfigMaps.
73+
74+
A new field will be added to the ClusterBuilder/Builder resources allowing the user to provide a reference to a lifecycle CR.
75+
This field will be optional and will default to the highest semantic version that is supported by the buildpacks in the builder and the platform.
76+
This is similar to how we determine the platform api to use for a build.
77+
```yaml
78+
apiVersion: kpack.io/v1alpha2
79+
kind: Builder
80+
metadata:
81+
name: my-builder
82+
spec:
83+
tag: gcr.io/sample/builder
84+
serviceAccountName: default
85+
stack:
86+
name: stack
87+
kind: ClusterStack
88+
lifecycle:
89+
name: my-lifecycle
90+
kind: ClusterLifecycle
91+
order:
92+
- group:
93+
- id: paketo-buildpacks/java
94+
```
95+
96+
```yaml
97+
apiVersion: kpack.io/v1alpha2
98+
kind: ClusterBuilder
99+
metadata:
100+
name: my-cluster-builder
101+
spec:
102+
tag: gcr.io/sample/builder
103+
stack:
104+
name: bionic-stack
105+
kind: ClusterStack
106+
lifecycle:
107+
name: my-lifecycle
108+
kind: ClusterLifecycle
109+
serviceAccountRef:
110+
name: default
111+
namespace: default
112+
order:
113+
- group:
114+
- id: paketo-buildpacks/java
115+
```
116+
117+
Creating a CRD for the lifecycle will allow us to do the following:
118+
- Provide status resource that shows more information about the lifecycle such as supported api versions
119+
- Allow users to specify a particular lifecycle for their builder, mimicking behavior that currently exists in the pack cli
120+
- Offer a clean shift to using the upstream lifecycle image if done in conjunction with deprecation of windows support
121+
122+
**Complexity:**
123+
124+
The complexity of this is not that high due to its similarity with the other kpack resources.
125+
126+
**Prior Art:**
127+
128+
- The pack cli allows a lifecycle image to be specified when creating a build
129+
- Adding new resources to the builder that get added to a layer has been done before in kpack
130+
131+
**Alternatives:**
132+
133+
We could keep the existing experience.
134+
135+
**Risks:**
136+
Exposing the user to the lifecycle can result in some confusion, but this can be mitigated by not making it a required
137+
field on the builder and continuing to ship a lifecycle out of the box.

0 commit comments

Comments
 (0)