mirror of https://github.com/k3s-io/k3s
Merge pull request #57958 from nikhita/sample-controller-crd-validation
Automatic merge from submit-queue (batch tested with PRs 57902, 57958). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add CustomResourceValidation example in sample-controller Add `CustomResourceValidation` example in sample-controller. Addresses the following part of https://github.com/kubernetes/sample-controller/issues/2: > CRDs support json-schema schemas. These CRDs don't have them. It would be nice to show how to add them **Release note**: ```release-note NONE ``` /assign sttts munnerzpull/6/head
commit
51acead084
|
@ -73,6 +73,22 @@ type User struct {
|
|||
}
|
||||
```
|
||||
|
||||
## Validation
|
||||
|
||||
To validate custom resources, use the [`CustomResourceValidation`](https://kubernetes.io/docs/tasks/access-kubernetes-api/extend-api-custom-resource-definitions/#validation) feature.
|
||||
|
||||
This feature is beta and enabled by default in v1.9. If you are using v1.8, enable the feature using
|
||||
the `CustomResourceValidation` feature gate on the [kube-apiserver](https://kubernetes.io/docs/admin/kube-apiserver):
|
||||
|
||||
```sh
|
||||
--feature-gates=CustomResourceValidation=true
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
The schema in the [example CRD](./artifacts/examples/crd.yaml) applies the following validation on the custom resource:
|
||||
`spec.replicas` must be an integer and must have a minimum value of 1 and a maximum value of 10.
|
||||
|
||||
## Cleanup
|
||||
|
||||
You can clean up the created CustomResourceDefinition with:
|
||||
|
|
|
@ -9,3 +9,12 @@ spec:
|
|||
kind: Foo
|
||||
plural: foos
|
||||
scope: Namespaced
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
spec:
|
||||
properties:
|
||||
replicas:
|
||||
type: integer
|
||||
minimum: 1
|
||||
maximum: 10
|
||||
|
|
Loading…
Reference in New Issue