CRD Validation

These markers modify how the CRD validation schema is produced for the types and fields they modify. Each corresponds roughly to an OpenAPI/JSON schema option.

See Generating CRDs for examples.

kubebuilder:validation:Enum
any
specifies that this (scalar) field is restricted to the *exact* values specified here.
any
kubebuilder:validation:Enum
any
specifies that this (scalar) field is restricted to the *exact* values specified here.
any
kubebuilder:validation:ExclusiveMaximum
bool
indicates that the maximum is "up to" but not including that value.
bool
kubebuilder:validation:ExclusiveMaximum
bool
indicates that the maximum is "up to" but not including that value.
bool
kubebuilder:validation:ExclusiveMinimum
bool
indicates that the minimum is "up to" but not including that value.
bool
kubebuilder:validation:ExclusiveMinimum
bool
indicates that the minimum is "up to" but not including that value.
bool
kubebuilder:validation:Format
string
specifies additional "complex" formatting for this field.

For example, a date-time field would be marked as “type: string“ and “format: date-time“.

string
kubebuilder:validation:Format
string
specifies additional "complex" formatting for this field.

For example, a date-time field would be marked as “type: string“ and “format: date-time“.

string
kubebuilder:validation:MaxItems
int
specifies the maximum length for this list.
int
kubebuilder:validation:MaxItems
int
specifies the maximum length for this list.
int
kubebuilder:validation:MaxLength
int
specifies the maximum length for this string.
int
kubebuilder:validation:MaxLength
int
specifies the maximum length for this string.
int
kubebuilder:validation:Maximum
int
specifies the maximum numeric value that this field can have.
int
kubebuilder:validation:Maximum
int
specifies the maximum numeric value that this field can have.
int
kubebuilder:validation:MinItems
int
specifies the minimun length for this list.
int
kubebuilder:validation:MinItems
int
specifies the minimun length for this list.
int
kubebuilder:validation:MinLength
int
specifies the minimum length for this string.
int
kubebuilder:validation:MinLength
int
specifies the minimum length for this string.
int
kubebuilder:validation:Minimum
int
specifies the minimum numeric value that this field can have.
int
kubebuilder:validation:Minimum
int
specifies the minimum numeric value that this field can have.
int
kubebuilder:validation:MultipleOf
int
specifies that this field must have a numeric value that's a multiple of this one.
int
kubebuilder:validation:MultipleOf
int
specifies that this field must have a numeric value that's a multiple of this one.
int
kubebuilder:validation:Optional
specifies that this field is optional, if fields are required by default.
kubebuilder:validation:Optional
specifies that all fields in this package are optional by default.
kubebuilder:validation:Pattern
string
specifies that this string must match the given regular expression.
string
kubebuilder:validation:Pattern
string
specifies that this string must match the given regular expression.
string
kubebuilder:validation:Required
specifies that this field is required, if fields are optional by default.
kubebuilder:validation:Required
specifies that all fields in this package are required by default.
kubebuilder:validation:Type
string
overrides the type for this field (which defaults to the equivalent of the Go type).

This generally must be paired with custom serialization. For example, the metav1.Time field would be marked as “type: string“ and “format: date-time“.

string
kubebuilder:validation:Type
string
overrides the type for this field (which defaults to the equivalent of the Go type).

This generally must be paired with custom serialization. For example, the metav1.Time field would be marked as “type: string“ and “format: date-time“.

string
kubebuilder:validation:UniqueItems
bool
specifies that all items in this list must be unique.
bool
kubebuilder:validation:UniqueItems
bool
specifies that all items in this list must be unique.
bool
nullable
marks this field as allowing the "null" value.

This is often not necessary, but may be helpful with custom serialization.

optional
specifies that this field is optional, if fields are required by default.