Skip to content

Commit debec6a

Browse files
authored
Merge pull request #23516 from tengqm/fix-crd
Fix nits in CRD task
2 parents 71e55e4 + 321342b commit debec6a

File tree

1 file changed

+57
-48
lines changed

1 file changed

+57
-48
lines changed

content/en/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ kubectl get ct -o yaml
150150
```
151151

152152
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:
154154

155155
```yaml
156156
apiVersion: v1
@@ -174,7 +174,7 @@ metadata:
174174
175175
## Delete a CustomResourceDefinition
176176
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
178178
and delete all custom objects stored in it.
179179
180180
```shell
@@ -190,11 +190,17 @@ If you later recreate the same CustomResourceDefinition, it will start out empty
190190

191191
## Specifying a structural schema
192192

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.
194198

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.
196202

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:
198204

199205
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:
200206
* a node with `x-kubernetes-int-or-string: true`
@@ -274,7 +280,7 @@ is not a structural schema because of the following violations:
274280
* `bar` inside of `anyOf` is not specified outside (rule 2).
275281
* `bar`'s `type` is within `anyOf` (rule 3).
276282
* 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).
278284

279285
In contrast, the following, corresponding schema is structural:
280286
```yaml
@@ -308,7 +314,7 @@ CustomResourceDefinitions store validated resource data in the cluster's persist
308314
{{< note >}}
309315
CRDs converted from `apiextensions.k8s.io/v1beta1` to `apiextensions.k8s.io/v1` might lack structural schemas, and `spec.preserveUnknownFields` might be `true`.
310316

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.
312318
{{< /note >}}
313319

314320
If you save the following YAML to `my-crontab.yaml`:
@@ -350,12 +356,12 @@ spec:
350356
Notice that the field `someRandomField` was pruned.
351357

352358
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)
354360
to clients, `kubectl` also checks for unknown fields and rejects those objects well before they would be sent to the API server.
355361

356362
#### Controlling pruning
357363

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).
359365
For example:
360366

361367
```yaml
@@ -458,7 +464,7 @@ allOf:
458464

459465
With one of those specification, both an integer and a string validate.
460466

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),
462468
`x-kubernetes-int-or-string: true` is unfolded to one of the two patterns shown above.
463469

464470
### RawExtension
@@ -520,7 +526,7 @@ of a resource is not possible while they exist.
520526

521527
The first delete request on an object with finalizers sets a value for the
522528
`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.
524530

525531
When the `metadata.deletionTimestamp` field is set, controllers watching the object
526532
execute any finalizers they handle, by polling update requests for that
@@ -537,7 +543,9 @@ meaning all finalizers have been executed.
537543
### Validation
538544

539545
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).
546+
[OpenAPI v3 schemas](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject)
547+
and you can add additional validation using
548+
[admission webhooks](/docs/reference/access-authn-authz/admission-controllers/#validatingadmissionwebhook).
541549

542550
Additionally, the following restrictions are applied to the schema:
543551

@@ -552,17 +560,18 @@ Additionally, the following restrictions are applied to the schema:
552560
- `writeOnly`,
553561
- `xml`,
554562
- `$ref`.
555-
- The field `uniqueItems` cannot be set to _true_.
556-
- The field `additionalProperties` cannot be set to _false_.
563+
- The field `uniqueItems` cannot be set to `true`.
564+
- The field `additionalProperties` cannot be set to `false`.
557565
- The field `additionalProperties` is mutually exclusive with `properties`.
558566

559-
These fields can only be set with specific features enabled:
567+
The `default` field can be set when the [Defaulting feature](#defaulting) is enabled,
568+
which is the case with `apiextensions.k8s.io/v1` CustomResourceDefinitions.
569+
Defaulting is in GA since 1.17 (beta since 1.16 with the `CustomResourceDefaulting`
570+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
571+
enabled, which is the case automatically for many clusters for beta features).
560572

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.
566575

567576
The schema is defined in the CustomResourceDefinition. In the following example, the
568577
CustomResourceDefinition applies the following validations on the custom object:
@@ -756,7 +765,7 @@ Default values for `metadata` fields of `x-kubernetes-embedded-resources: true`
756765

757766
### Publish Validation Schema in OpenAPI v2
758767

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.
760769

761770
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.
762771

@@ -853,7 +862,7 @@ The `NAME` column is implicit and does not need to be defined in the CustomResou
853862

854863
#### Priority
855864

856-
Each column includes a `priority` field for each column. Currently, the priority
865+
Each column includes a `priority` field. Currently, the priority
857866
differentiates between columns shown in standard view or wide view (using the `-o wide` flag).
858867

859868
- 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
866875
- `integer` – non-floating-point numbers
867876
- `number` – floating point numbers
868877
- `string` – strings
869-
- `boolean` – true or false
878+
- `boolean` `true` or `false`
870879
- `date` – rendered differentially as time since this timestamp.
871880

872881
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
906915
- The `.metadata.generation` value is incremented for all changes, except for changes to `.metadata` or `.status`.
907916
- Only the following constructs are allowed at the root of the CRD OpenAPI validation schema:
908917

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`
929938

930939
#### Scale subresource
931940

932941
When the scale subresource is enabled, the `/scale` subresource for the custom resource is exposed.
933942
The `autoscaling/v1.Scale` object is sent as the payload for `/scale`.
934943

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.
936945

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`.
938947

939948
- It is a required value.
940949
- 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,
942951
the `/scale` subresource will return an error on GET.
943952

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`.
945954

946955
- It is a required value.
947956
- Only JSONPaths under `.status` and with the dot notation are allowed.
@@ -1141,7 +1150,7 @@ and create it:
11411150
kubectl apply -f my-crontab.yaml
11421151
```
11431152

1144-
You can specify the category using `kubectl get`:
1153+
You can specify the category when using `kubectl get`:
11451154

11461155
```
11471156
kubectl get all

0 commit comments

Comments
 (0)