You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md
+57-48Lines changed: 57 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,7 @@ kubectl get ct -o yaml
150
150
```
151
151
152
152
You should see that it contains the custom `cronSpec` and `image` fields
153
-
from the yaml you used to create it:
153
+
from the YAML you used to create it:
154
154
155
155
```yaml
156
156
apiVersion: v1
@@ -174,7 +174,7 @@ metadata:
174
174
175
175
## Delete a CustomResourceDefinition
176
176
177
-
When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint
177
+
When you delete a CustomResourceDefinition, the server will uninstall the RESTful API endpoint
178
178
and delete all custom objects stored in it.
179
179
180
180
```shell
@@ -190,11 +190,17 @@ If you later recreate the same CustomResourceDefinition, it will start out empty
190
190
191
191
## Specifying a structural schema
192
192
193
-
CustomResources store structured data in custom fiels (alongside the built-in fields `apiVersion`, `kind` and `metadata`, which the API server validates implicitly). With [OpenAPI v3.0 validation](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) a schema can be specified, which is validated during creation and updates, compare below for details and limits of such a schema.
193
+
CustomResources store structured data in custom fields (alongside the built-in
194
+
fields `apiVersion`, `kind` and `metadata`, which the API server validates
195
+
implicitly). With [OpenAPI v3.0 validation](#validation) a schema can be
196
+
specified, which is validated during creation and updates, compare below for
197
+
details and limits of such a schema.
194
198
195
-
With `apiextensions.k8s.io/v1` the definition of a structural schema is mandatory for CustomResourceDefinitions (in the beta version of CustomResourceDefinition, structural schemas were optional).
199
+
With `apiextensions.k8s.io/v1` the definition of a structural schema is
200
+
mandatory for CustomResourceDefinitions. In the beta version of
201
+
CustomResourceDefinition, the structural schema was optional.
196
202
197
-
A structural schema is an [OpenAPI v3.0 validation schema](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) which:
203
+
A structural schema is an [OpenAPI v3.0 validation schema](#validation) which:
198
204
199
205
1. specifies a non-empty type (via `type` in OpenAPI) for the root, for each specified field of an object node (via `properties` or `additionalProperties` in OpenAPI) and for each item in an array node (via `items` in OpenAPI), with the exception of:
200
206
* a node with `x-kubernetes-int-or-string: true`
@@ -274,7 +280,7 @@ is not a structural schema because of the following violations:
274
280
* `bar` inside of `anyOf` is not specified outside (rule 2).
275
281
* `bar`'s `type` is within `anyOf` (rule 3).
276
282
* the description is set within `anyOf` (rule 3).
277
-
* `metadata.finalizer` might not be restricted (rule 4).
283
+
* `metadata.finalizers` might not be restricted (rule 4).
278
284
279
285
In contrast, the following, corresponding schema is structural:
280
286
```yaml
@@ -308,7 +314,7 @@ CustomResourceDefinitions store validated resource data in the cluster's persist
308
314
{{< note >}}
309
315
CRDs converted from `apiextensions.k8s.io/v1beta1` to `apiextensions.k8s.io/v1` might lack structural schemas, and `spec.preserveUnknownFields` might be `true`.
310
316
311
-
For migrated CustomResourceDefinitions where `spec.preserveUnknownFields` is set, pruning is _not_ enabled and you can store arbitrary data. For best compatibility, you should update customer resources to meet an OpenAPI schema, and you should set `spec.preserveUnknownFields` true for the CustomResourceDefinition itself.
317
+
For migrated CustomResourceDefinitions where `spec.preserveUnknownFields` is set, pruning is _not_ enabled and you can store arbitrary data. For best compatibility, you should update your custom resources to meet an OpenAPI schema, and you should set `spec.preserveUnknownFields` to true for the CustomResourceDefinition itself.
312
318
{{< /note >}}
313
319
314
320
If you save the following YAML to `my-crontab.yaml`:
@@ -350,12 +356,12 @@ spec:
350
356
Notice that the field `someRandomField` was pruned.
351
357
352
358
This example turned off client-side validation to demonstrate the API server's behavior, by adding the `--validate=false` command line option.
353
-
Because the [OpenAPI validation schemas are also published](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2)
359
+
Because the [OpenAPI validation schemas are also published](#publish-validation-schema-in-openapi-v2)
354
360
to clients, `kubectl` also checks for unknown fields and rejects those objects well before they would be sent to the API server.
355
361
356
362
#### Controlling pruning
357
363
358
-
By default, all unspecified fields for a custom resource, across all versions, are pruned. It is possible though to opt-out of that for specifc sub-trees fof fields by adding `x-kubernetes-preserve-unknown-fields: true` in the [structural OpenAPI v3 validation schema](#specifying-a-structural-schema).
364
+
By default, all unspecified fields for a custom resource, across all versions, are pruned. It is possible though to opt-out of that for specifc sub-trees of fields by adding `x-kubernetes-preserve-unknown-fields: true` in the [structural OpenAPI v3 validation schema](#specifying-a-structural-schema).
359
365
For example:
360
366
361
367
```yaml
@@ -458,7 +464,7 @@ allOf:
458
464
459
465
With one of those specification, both an integer and a string validate.
460
466
461
-
In [Validation Schema Publishing](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#publish-validation-schema-in-openapi-v2),
467
+
In [Validation Schema Publishing](#publish-validation-schema-in-openapi-v2),
462
468
`x-kubernetes-int-or-string: true` is unfolded to one of the two patterns shown above.
463
469
464
470
### RawExtension
@@ -520,7 +526,7 @@ of a resource is not possible while they exist.
520
526
521
527
The first delete request on an object with finalizers sets a value for the
522
528
`metadata.deletionTimestamp`field but does not delete it. Once this value is set,
523
-
entries in the `finalizer` list can only be removed.
529
+
entries in the `finalizers` list can only be removed.
524
530
525
531
When the `metadata.deletionTimestamp` field is set, controllers watching the object
526
532
execute any finalizers they handle, by polling update requests for that
@@ -537,7 +543,9 @@ meaning all finalizers have been executed.
537
543
### Validation
538
544
539
545
Custom resources are validated via
540
-
[OpenAPI v3 schemas](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject) and you can add additional validation using [admission webhooks](/docs/reference/access-authn-authz/admission-controllers/#validatingadmissionwebhook).
enabled, which is the case automatically for many clusters for beta features).
560
572
561
-
You can also use [Validation Schema Defaulting](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting) to apply default values.
562
-
563
-
{{< note >}}
564
-
Compare with [structural schemas](#specifying-a-structural-schema) for further restriction required for certain CustomResourceDefinition features.
565
-
{{< /note >}}
573
+
Refer to the [structural schemas](#specifying-a-structural-schema) section for other
574
+
restrictions and CustomResourceDefinition features.
566
575
567
576
The schema is defined in the CustomResourceDefinition. In the following example, the
568
577
CustomResourceDefinition applies the following validations on the custom object:
@@ -756,7 +765,7 @@ Default values for `metadata` fields of `x-kubernetes-embedded-resources: true`
756
765
757
766
### Publish Validation Schema in OpenAPI v2
758
767
759
-
CustomResourceDefinition [OpenAPI v3 validation schemas](#validation) which are [structural](#specifying-a-structural-schema) and [enable pruning](#preserving-unknown-fields) are published as part of the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) from Kubernetes API server.
768
+
CustomResourceDefinition [OpenAPI v3 validation schemas](#validation) which are [structural](#specifying-a-structural-schema) and [enable pruning](#field-pruning) are published as part of the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) from Kubernetes API server.
760
769
761
770
The [kubectl](/docs/reference/kubectl/overview) command-line tool consumes the published schema to perform client-side validation (`kubectl create` and `kubectl apply`), schema explanation (`kubectl explain`) on custom resources. The published schema can be consumed for other purposes as well, like client generation or documentation.
762
771
@@ -853,7 +862,7 @@ The `NAME` column is implicit and does not need to be defined in the CustomResou
853
862
854
863
#### Priority
855
864
856
-
Each column includes a `priority` field for each column. Currently, the priority
865
+
Each column includes a `priority` field. Currently, the priority
857
866
differentiates between columns shown in standard view or wide view (using the `-o wide` flag).
858
867
859
868
- Columns with priority `0` are shown in standard view.
@@ -866,7 +875,7 @@ A column's `type` field can be any of the following (compare [OpenAPI v3 data ty
866
875
- `integer`– non-floating-point numbers
867
876
- `number`– floating point numbers
868
877
- `string`– strings
869
-
- `boolean`– true or false
878
+
- `boolean`– `true` or `false`
870
879
- `date`– rendered differentially as time since this timestamp.
871
880
872
881
If the value inside a CustomResource does not match the type specified for the column,
@@ -906,42 +915,42 @@ When the status subresource is enabled, the `/status` subresource for the custom
906
915
- The `.metadata.generation` value is incremented for all changes, except for changes to `.metadata` or `.status`.
907
916
- Only the following constructs are allowed at the root of the CRD OpenAPI validation schema:
908
917
909
-
- Description
910
-
- Example
911
-
- ExclusiveMaximum
912
-
- ExclusiveMinimum
913
-
- ExternalDocs
914
-
- Format
915
-
- Items
916
-
- Maximum
917
-
- MaxItems
918
-
- MaxLength
919
-
- Minimum
920
-
- MinItems
921
-
- MinLength
922
-
- MultipleOf
923
-
- Pattern
924
-
- Properties
925
-
- Required
926
-
- Title
927
-
- Type
928
-
- UniqueItems
918
+
- `description`
919
+
- `example`
920
+
- `exclusiveMaximum`
921
+
- `exclusiveMinimum`
922
+
- `externalDocs`
923
+
- `format`
924
+
- `items`
925
+
- `maximum`
926
+
- `maxItems`
927
+
- `maxLength`
928
+
- `minimum`
929
+
- `minItems`
930
+
- `minLength`
931
+
- `multipleOf`
932
+
- `pattern`
933
+
- `properties`
934
+
- `required`
935
+
- `title`
936
+
- `type`
937
+
- `uniqueItems`
929
938
930
939
#### Scale subresource
931
940
932
941
When the scale subresource is enabled, the `/scale` subresource for the custom resource is exposed.
933
942
The `autoscaling/v1.Scale` object is sent as the payload for `/scale`.
934
943
935
-
To enable the scale subresource, the following values are defined in the CustomResourceDefinition.
944
+
To enable the scale subresource, the following fields are defined in the CustomResourceDefinition.
936
945
937
-
- `SpecReplicasPath`defines the JSONPath inside of a custom resource that corresponds to `Scale.Spec.Replicas`.
946
+
- `specReplicasPath`defines the JSONPath inside of a custom resource that corresponds to `scale.spec.replicas`.
938
947
939
948
- It is a required value.
940
949
- Only JSONPaths under `.spec` and with the dot notation are allowed.
941
-
- If there is no value under the `SpecReplicasPath` in the custom resource,
950
+
- If there is no value under the `specReplicasPath` in the custom resource,
942
951
the `/scale` subresource will return an error on GET.
943
952
944
-
- `StatusReplicasPath`defines the JSONPath inside of a custom resource that corresponds to `Scale.Status.Replicas`.
953
+
- `statusReplicasPath`defines the JSONPath inside of a custom resource that corresponds to `scale.status.replicas`.
945
954
946
955
- It is a required value.
947
956
- Only JSONPaths under `.status` and with the dot notation are allowed.
@@ -1141,7 +1150,7 @@ and create it:
1141
1150
kubectl apply -f my-crontab.yaml
1142
1151
```
1143
1152
1144
-
You can specify the category using `kubectl get`:
1153
+
You can specify the category when using `kubectl get`:
0 commit comments