Skip to content

Commit f4dd3b1

Browse files
lancelilic
authored andcommitted
doc: add OpenAPI validation info to user guide (#1640)
* doc: add OpenAPI validation info to user guide The generated YAML CRD created when running `operator-sdk add api ...` includes an OpenAPI v3.0 validation section. E.g. ```YAML validation: openAPIV3Schema: properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' type: string kind: description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' type: string metadata: type: object spec: type: object status: type: object ``` The properties for a CRD should be specified here for validation. In the case of the Memcached example, a `size` property should be added to the generated CRD. This change documents that process in the user guide.
1 parent ee54f0c commit f4dd3b1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

doc/user-guide.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ After modifying the `*_types.go` file always run the following command to update
101101
$ operator-sdk generate k8s
102102
```
103103

104+
### OpenAPI validation
105+
To update the OpenAPI validation section in the CRD `deploy/crds/cache_v1alpha1_memcached_crd.yaml`, run the following command.
106+
107+
```console
108+
$ operator-sdk generate openapi
109+
```
110+
This validation section allows Kubernetes to validate the properties in a Memcached Custom Resource when it is created or updated. An example of the generated YAML is as follows:
111+
112+
```YAML
113+
spec:
114+
validation:
115+
openAPIV3Schema:
116+
properties:
117+
spec:
118+
properties:
119+
size:
120+
format: int32
121+
type: integer
122+
```
123+
124+
To learn more about OpenAPI v3.0 validation schemas in Custom Resource Definitions, refer to the [Kubernetes Documentation][doc_validation_schema].
125+
126+
104127
## Add a new Controller
105128
106129
Add a new [Controller][controller-go-doc] to the project that will watch and reconcile the Memcached resource:
@@ -623,3 +646,4 @@ When the operator is not running in a cluster, the Manager will return an error
623646
[result_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Result
624647
[metrics_doc]: ./user/metrics/README.md
625648
[quay_link]: https://quay.io
649+
[doc_validation_schema]: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#specifying-a-structural-schema

0 commit comments

Comments
 (0)