spec.versions.schema.openAPIV3Schema and follows the standard OpenAPI v3 structural schema. At the top level you describe a tree of type, properties, and required fields. For example:
type: object at the root, then walk down into spec and status the same way. Each field in the schema supports constraints; these common constraints let you validate names, sizes, ranges, and structural rules before your controller needs to handle invalid input.
Callouts
Use an OpenAPI structural schema to reject invalid CRs early — this simplifies controller logic and prevents reconciliation loops caused by malformed objects.
Strings
minLength,maxLengthpattern(regular expression)enumfor closed sets
minimum,maximum,exclusiveMinimum(boolean)
minItems,maxItems,uniqueItems
- The
requiredlist on any object enumerates which child properties must be present. If a required field is missing, writes will be rejected.
- You can set
defaultin the schema. When a user omits that field, the API server fills it on write so your controller doesn’t have to handle the empty case.
- Structural schemas cause automatic pruning. In Kubernetes, a structural schema is a fully typed template: anything not declared on that template is stripped before storage. Pruning prevents users from stashing arbitrary data inside your CR.
x-kubernetes-preserve-unknown-fields extension:
x-kubernetes-int-or-string— accepts either integer or string (used by core Kubernetes APIs for ports and quantities).
x-kubernetes-validations— where expression-based validation rules live. These use CEL (Common Expression Language, https://github.com/google/cel-spec) and run in the API server (no admission webhook required). CEL is ideal for cross-field checks that OpenAPI cannot express.
- When you change a schema on an existing CRD, already stored objects are not revalidated; only new writes are checked. Tightening constraints can fail new writes even though old objects remain stored. Version your API and plan schema migrations carefully.
When you tighten a schema, existing stored objects are not automatically revalidated. Plan schema migrations and API versioning carefully.
- You will write a CRD by hand for the webapp resource and observe these validators rejecting bad input before it reaches your controller.

- OpenAPI Specification v3: https://spec.openapis.org/oas/v3.0.3
- Kubernetes CRD validation and structural schemas: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/
- CEL for Kubernetes validation: https://github.com/google/cel-spec