Skip to content

Commit b05f4fc

Browse files
committed
Add CRD Upgrade Safety documentation
Signed-off-by: Tayler Geiger <[email protected]>
1 parent ff0ce68 commit b05f4fc

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

docs/refs/crd-upgrade-safety.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Custom Resource Definition Upgrade Safety
2+
3+
OLM implements several validation checks when upgrading Custom Resource Definitions
4+
in order to maintain backwards compatibility with previous versions of that CRD.
5+
These validation checks are known collectively as the CRD Upgrade Safety preflight check.
6+
7+
The CRD Upgrade Safety preflight check consists of several individual field validations
8+
that are performed before an upgrade to a CRD is allowed to progress on a cluster.
9+
10+
## Disallowed CRD Upgrade Changes
11+
12+
The following changes to an existing CRD will be caught by the CRD Upgrade
13+
Safety preflight check and prevent the upgrade:
14+
- The scope changes from Cluster to Namespace or from Namespace to Cluster
15+
- An existing stored version of the CRD is removed
16+
- A new required field is added to an existing version of the CRD
17+
- An existing field is removed from an existing version of the CRD
18+
- An existing field type is changed in an existing version of the CRD
19+
- A new default value is added to a field that did not previously have a default value
20+
- The default value of a field is changed
21+
- An existing default value of a field is removed
22+
- New enum restrictions are added to an existing field which did not previously have enum restrictions
23+
- Existing enum values from an existing field are removed
24+
- The minimum value of an existing field is incrased in an existing version
25+
- The maximum value of an existing field is decreased in an existing version
26+
- Minimum or maximum field constraints are added to a field that did not previously have constraints
27+
28+
If the CRD Upgrade Safety preflight check encounters one of the disallowed upgrade changes,
29+
it will log an error for each disallowed change detected in the CRD upgrade.
30+
31+
In cases where a change to the CRD does not fall into one of the disallowed change categories
32+
but is also unable to be properly detected as allowed, the CRD Upgrade Safety preflight check
33+
will prevent the upgrade and log an error for an "unknown change."
34+
35+
**Note:** the rules for changes to minimum and maximum values apply to `minimum`, `minLength`,
36+
`minProperties`, `minItems`, `maximum`, `maxLength`, `maxProperties`, and `maxItems` constrants.
37+
38+
## Allowed CRD Upgrade Changes
39+
40+
The following changes to an existing CRD are safe for backwards compatibility and will
41+
not cause the CRD Upgrade Safety preflight check to halt the upgrade:
42+
- Adding new enum values to the list of allowed enum values in a field
43+
- An existing required field is changed to optional in an existing version
44+
- The minimum value of an existing field is decreased in an existing version
45+
- The maximum value of an existing field is increased in an existing version
46+
- A new version of the CRD is added with no modifications to existing versions
47+
48+
49+
## Disabling CRD Upgrade Safety
50+
51+
The CRD Upgrade Safety preflight check can be entirely disabled by adding the
52+
`preflight.crdUpgradeSafety.disabled` field with a value of "true" to the ClusterExtension of the CRD.
53+
54+
```yaml
55+
apiVersion: olm.operatorframework.io/v1alpha1
56+
kind: ClusterExtension
57+
metadata:
58+
name: clusterextension-sample
59+
spec:
60+
installNamespace: default
61+
packageName: argocd-operator
62+
version: 0.6.0
63+
preflight:
64+
crdUpgradeSafety:
65+
disabled: true
66+
```
67+
68+
Only the entire CRD Upgrade Safety preflight check can be disabled, not individual field validators.
69+
70+
**Note**: Disabling the CRD Upgrade Safety preflight check could break backwards compatibility with previous
71+
versions of the CRD and cause other unintended consequences on the cluster.
72+
73+
74+
## Examples of Unsafe CRD Changes
75+
76+
Take the following CRD as our starting version:
77+
78+
```yaml
79+
---
80+
apiVersion: apiextensions.k8s.io/v1
81+
kind: CustomResourceDefinition
82+
metadata:
83+
annotations:
84+
controller-gen.kubebuilder.io/version: v0.13.0
85+
name: example.test.example.com
86+
spec:
87+
group: test.example.com
88+
names:
89+
kind: Sample
90+
listKind: SampleList
91+
plural: samples
92+
singular: sample
93+
scope: Namespaced
94+
versions:
95+
- name: v1alpha1
96+
schema:
97+
openAPIV3Schema:
98+
properties:
99+
apiVersion:
100+
type: string
101+
kind:
102+
type: string
103+
metadata:
104+
type: object
105+
spec:
106+
type: object
107+
status:
108+
type: object
109+
pollInterval:
110+
type: string
111+
type: object
112+
served: true
113+
storage: true
114+
subresources:
115+
status: {}
116+
```
117+
118+
The following examples will demonstrate specific changes to sections of the example CRD
119+
that would be caught by the CRD Upgrade Safety preflight check.
120+
121+
### Changing Scope
122+
123+
In this example, `scope` has been changed from `Namespaced` to `Cluster`.
124+
```yaml
125+
spec:
126+
group: test.example.com
127+
names:
128+
kind: Sample
129+
listKind: SampleList
130+
plural: samples
131+
singular: sample
132+
scope: Cluster
133+
versions:
134+
- name: v1alpha1
135+
```
136+
137+
### Removing a previous version
138+
139+
In this example, the only previous version, `v1alpha1`, has been replaced with the new version:
140+
```yaml
141+
versions:
142+
- name: v1alpha2
143+
schema:
144+
openAPIV3Schema:
145+
properties:
146+
apiVersion:
147+
type: string
148+
kind:
149+
type: string
150+
metadata:
151+
type: object
152+
spec:
153+
type: object
154+
status:
155+
type: object
156+
pollInterval:
157+
type: string
158+
type: object
159+
```
160+
161+
### Removing an existing field
162+
163+
In this example, the `pollInterval` field has been removed from `v1alpha1`:
164+
```yaml
165+
versions:
166+
- name: v1alpha1
167+
schema:
168+
openAPIV3Schema:
169+
properties:
170+
apiVersion:
171+
type: string
172+
kind:
173+
type: string
174+
metadata:
175+
type: object
176+
spec:
177+
type: object
178+
status:
179+
type: object
180+
type: object
181+
```
182+
183+
### Adding a required field
184+
185+
In this example, `pollInterval` has been changed to a required field:
186+
```yaml
187+
versions:
188+
- name: v1alpha2
189+
schema:
190+
openAPIV3Schema:
191+
properties:
192+
apiVersion:
193+
type: string
194+
kind:
195+
type: string
196+
metadata:
197+
type: object
198+
spec:
199+
type: object
200+
status:
201+
type: object
202+
pollInterval:
203+
type: string
204+
type: object
205+
required:
206+
- pollInterval
207+
```

0 commit comments

Comments
 (0)