|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * extensions/ce/crd-upgrade-safety.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: REFERENCE |
| 6 | + |
| 7 | +[id="examples-unsafe_{context}"] |
| 8 | += Examples of unsafe CRD changes |
| 9 | + |
| 10 | +The following examples demonstrate specific changes to sections of an example custom resource definition (CRD) that would be caught by the CRD upgrade safety preflight check. |
| 11 | + |
| 12 | +For the following examples, consider a CRD object in the following starting state: |
| 13 | + |
| 14 | +.Example CRD object |
| 15 | +[%collapsible] |
| 16 | +==== |
| 17 | +[source,yaml] |
| 18 | +---- |
| 19 | +apiVersion: apiextensions.k8s.io/v1 |
| 20 | +kind: CustomResourceDefinition |
| 21 | +metadata: |
| 22 | + annotations: |
| 23 | + controller-gen.kubebuilder.io/version: v0.13.0 |
| 24 | + name: example.test.example.com |
| 25 | +spec: |
| 26 | + group: test.example.com |
| 27 | + names: |
| 28 | + kind: Sample |
| 29 | + listKind: SampleList |
| 30 | + plural: samples |
| 31 | + singular: sample |
| 32 | + scope: Namespaced |
| 33 | + versions: |
| 34 | + - name: v1alpha1 |
| 35 | + schema: |
| 36 | + openAPIV3Schema: |
| 37 | + properties: |
| 38 | + apiVersion: |
| 39 | + type: string |
| 40 | + kind: |
| 41 | + type: string |
| 42 | + metadata: |
| 43 | + type: object |
| 44 | + spec: |
| 45 | + type: object |
| 46 | + status: |
| 47 | + type: object |
| 48 | + pollInterval: |
| 49 | + type: string |
| 50 | + type: object |
| 51 | + served: true |
| 52 | + storage: true |
| 53 | + subresources: |
| 54 | + status: {} |
| 55 | +---- |
| 56 | +==== |
| 57 | + |
| 58 | +[id="scope-change_{context}"] |
| 59 | +== Scope change |
| 60 | + |
| 61 | +In the following custom resource definition (CRD) example, the `scope` field is changed from `Namespaced` to `Cluster`: |
| 62 | + |
| 63 | +.Example scope change in a CRD |
| 64 | +[%collapsible] |
| 65 | +==== |
| 66 | +[source,yaml] |
| 67 | +---- |
| 68 | + spec: |
| 69 | + group: test.example.com |
| 70 | + names: |
| 71 | + kind: Sample |
| 72 | + listKind: SampleList |
| 73 | + plural: samples |
| 74 | + singular: sample |
| 75 | + scope: Cluster |
| 76 | + versions: |
| 77 | + - name: v1alpha1 |
| 78 | +---- |
| 79 | +==== |
| 80 | + |
| 81 | +.Example error output |
| 82 | +[%collapsible] |
| 83 | +==== |
| 84 | +[source,text] |
| 85 | +---- |
| 86 | +validating upgrade for CRD "test.example.com" failed: CustomResourceDefinition test.example.com failed upgrade safety validation. "NoScopeChange" validation failed: scope changed from "Namespaced" to "Cluster" |
| 87 | +---- |
| 88 | +==== |
| 89 | + |
| 90 | +[id="stored-version-removal_{context}"] |
| 91 | +== Removal of a stored version |
| 92 | + |
| 93 | +In the following custom resource definition (CRD) example, the existing stored version, `v1alpha1`, is removed: |
| 94 | + |
| 95 | +.Example removal of a stored version in a CRD |
| 96 | +[%collapsible] |
| 97 | +==== |
| 98 | +[source,yaml] |
| 99 | +---- |
| 100 | + versions: |
| 101 | + - name: v1alpha2 |
| 102 | + schema: |
| 103 | + openAPIV3Schema: |
| 104 | + properties: |
| 105 | + apiVersion: |
| 106 | + type: string |
| 107 | + kind: |
| 108 | + type: string |
| 109 | + metadata: |
| 110 | + type: object |
| 111 | + spec: |
| 112 | + type: object |
| 113 | + status: |
| 114 | + type: object |
| 115 | + pollInterval: |
| 116 | + type: string |
| 117 | + type: object |
| 118 | +---- |
| 119 | +==== |
| 120 | + |
| 121 | +.Example error output |
| 122 | +[%collapsible] |
| 123 | +==== |
| 124 | +[source,text] |
| 125 | +---- |
| 126 | +validating upgrade for CRD "test.example.com" failed: CustomResourceDefinition test.example.com failed upgrade safety validation. "NoStoredVersionRemoved" validation failed: stored version "v1alpha1" removed |
| 127 | +---- |
| 128 | +==== |
| 129 | + |
| 130 | +[id="removal-existing-field_{context}"] |
| 131 | +== Removal of an existing field |
| 132 | + |
| 133 | +In the following custom resource definition (CRD) example, the `pollInterval` property field is removed from the `v1alpha1` schema: |
| 134 | + |
| 135 | +.Example removal of an existing field in a CRD |
| 136 | +[%collapsible] |
| 137 | +==== |
| 138 | +[source,yaml] |
| 139 | +---- |
| 140 | + versions: |
| 141 | + - name: v1alpha1 |
| 142 | + schema: |
| 143 | + openAPIV3Schema: |
| 144 | + properties: |
| 145 | + apiVersion: |
| 146 | + type: string |
| 147 | + kind: |
| 148 | + type: string |
| 149 | + metadata: |
| 150 | + type: object |
| 151 | + spec: |
| 152 | + type: object |
| 153 | + status: |
| 154 | + type: object |
| 155 | + type: object |
| 156 | +---- |
| 157 | +==== |
| 158 | + |
| 159 | +.Example error output |
| 160 | +[%collapsible] |
| 161 | +==== |
| 162 | +[source,text] |
| 163 | +---- |
| 164 | +validating upgrade for CRD "test.example.com" failed: CustomResourceDefinition test.example.com failed upgrade safety validation. "NoExistingFieldRemoved" validation failed: crd/test.example.com version/v1alpha1 field/^.spec.pollInterval may not be removed |
| 165 | +---- |
| 166 | +==== |
| 167 | + |
| 168 | +[id="addition-required-field_{context}"] |
| 169 | +== Addition of a required field |
| 170 | + |
| 171 | +In the following custom resource definition (CRD) example, the `pollInterval` property has been changed to a required field: |
| 172 | + |
| 173 | +.Example addition of a required field in a CRD |
| 174 | +[%collapsible] |
| 175 | +==== |
| 176 | +[source,yaml] |
| 177 | +---- |
| 178 | + versions: |
| 179 | + - name: v1alpha2 |
| 180 | + schema: |
| 181 | + openAPIV3Schema: |
| 182 | + properties: |
| 183 | + apiVersion: |
| 184 | + type: string |
| 185 | + kind: |
| 186 | + type: string |
| 187 | + metadata: |
| 188 | + type: object |
| 189 | + spec: |
| 190 | + type: object |
| 191 | + status: |
| 192 | + type: object |
| 193 | + pollInterval: |
| 194 | + type: string |
| 195 | + type: object |
| 196 | + required: |
| 197 | + - pollInterval |
| 198 | +---- |
| 199 | +==== |
| 200 | + |
| 201 | +.Example error output |
| 202 | +[%collapsible] |
| 203 | +==== |
| 204 | +[source,text] |
| 205 | +---- |
| 206 | +validating upgrade for CRD "test.example.com" failed: CustomResourceDefinition test.example.com failed upgrade safety validation. "ChangeValidator" validation failed: version "v1alpha1", field "^": new required fields added: [pollInterval] |
| 207 | +---- |
| 208 | +==== |
0 commit comments