Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

// +required
specifies that this field is required.
// +optional
specifies that this field is optional.
// +nullable
marks this field as allowing the "null" value.

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

Example:

// +nullable
Description *string
// +kubebuilder:validation:items:XValidation
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
for array items marks a field as requiring a value for which a given

expression evaluates to true.

This marker may be repeated to specify multiple expressions, all of which must evaluate to true.

Examples:

// Basic field validation
// +kubebuilder:validation:XValidation:rule="self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas",message="replicas must be between minReplicas and maxReplicas"

// Validation with custom reason
// +kubebuilder:validation:XValidation:rule="self.x <= self.maxX",message="x cannot be greater than maxX",reason="FieldValueInvalid"

// Immutability check
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
// +kubebuilder:validation:items:XValidation
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
for array items marks a field as requiring a value for which a given

expression evaluates to true.

This marker may be repeated to specify multiple expressions, all of which must evaluate to true.

Examples:

// Basic field validation
// +kubebuilder:validation:XValidation:rule="self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas",message="replicas must be between minReplicas and maxReplicas"

// Validation with custom reason
// +kubebuilder:validation:XValidation:rule="self.x <= self.maxX",message="x cannot be greater than maxX",reason="FieldValueInvalid"

// Immutability check
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
// +kubebuilder:validation:items:XIntOrString
for array items marks a fields as an IntOrString.

This is required when applying patterns or other validations to an IntOrString field. Known information about the type is applied during the collapse phase and as such is not normally available during marker application.

Example:

// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^(\\d+|\\d+%|)$"
Port intstr.IntOrString
// +kubebuilder:validation:items:XIntOrString
for array items marks a fields as an IntOrString.

This is required when applying patterns or other validations to an IntOrString field. Known information about the type is applied during the collapse phase and as such is not normally available during marker application.

Example:

// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^(\\d+|\\d+%|)$"
Port intstr.IntOrString
// +kubebuilder:validation:items:XEmbeddedResource
for array items marks a fields as an embedded resource with apiVersion, kind and metadata fields.

An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.

Example:

// +kubebuilder:validation:EmbeddedResource
Template runtime.RawExtension
// +kubebuilder:validation:items:XEmbeddedResource
for array items marks a fields as an embedded resource with apiVersion, kind and metadata fields.

An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.

Example:

// +kubebuilder:validation:EmbeddedResource
Template runtime.RawExtension
// +kubebuilder:validation:items:UniqueItems
bool
for array items specifies that all items in this list must be unique.

Example:

// +kubebuilder:validation:UniqueItems=true
Tags []string
bool
// +kubebuilder:validation:items:UniqueItems
bool
for array items specifies that all items in this list must be unique.

Example:

// +kubebuilder:validation:UniqueItems=true
Tags []string
bool
// +kubebuilder:validation:items:Type
string
for array items 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".

Common types include: "string", "number", "integer", "boolean", "array", "object".

Example:

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
Time metav1.Time
string
// +kubebuilder:validation:items:Type
string
for array items 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".

Common types include: "string", "number", "integer", "boolean", "array", "object".

Example:

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
Time metav1.Time
string
// +kubebuilder:validation:items:Pattern
string
for array items specifies that this string must match the given regular expression.

Example (DNS subdomain):

// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
DNSName string
string
// +kubebuilder:validation:items:Pattern
string
for array items specifies that this string must match the given regular expression.

Example (DNS subdomain):

// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
DNSName string
string
// +kubebuilder:validation:items:MultipleOf
for array items specifies that this field must have a numeric value that's a multiple of this one.

Example (value must be a multiple of 5):

// +kubebuilder:validation:MultipleOf=5
Count int32
// +kubebuilder:validation:items:MultipleOf
for array items specifies that this field must have a numeric value that's a multiple of this one.

Example (value must be a multiple of 5):

// +kubebuilder:validation:MultipleOf=5
Count int32
// +kubebuilder:validation:items:Minimum
for array items specifies the minimum numeric value that this field can have. Negative numbers are supported.

Example:

// +kubebuilder:validation:Minimum=0
Replicas int32
// +kubebuilder:validation:items:Minimum
for array items specifies the minimum numeric value that this field can have. Negative numbers are supported.

Example:

// +kubebuilder:validation:Minimum=0
Replicas int32
// +kubebuilder:validation:items:MinProperties
int
for array items restricts the number of keys in an object

Example:

// +kubebuilder:validation:MinProperties=1
Metadata map[string]string
int
// +kubebuilder:validation:items:MinProperties
int
for array items restricts the number of keys in an object

Example:

// +kubebuilder:validation:MinProperties=1
Metadata map[string]string
int
// +kubebuilder:validation:items:MinLength
int
for array items specifies the minimum length for this string.

Example:

// +kubebuilder:validation:MinLength=1
Name string
int
// +kubebuilder:validation:items:MinLength
int
for array items specifies the minimum length for this string.

Example:

// +kubebuilder:validation:MinLength=1
Name string
int
// +kubebuilder:validation:items:MinItems
int
for array items specifies the minimum length for this list.

Example:

// +kubebuilder:validation:MinItems=1
Endpoints []string
int
// +kubebuilder:validation:items:MinItems
int
for array items specifies the minimum length for this list.

Example:

// +kubebuilder:validation:MinItems=1
Endpoints []string
int
// +kubebuilder:validation:items:Maximum
for array items specifies the maximum numeric value that this field can have.

Example:

// +kubebuilder:validation:Maximum=100
Percentage int32
// +kubebuilder:validation:items:Maximum
for array items specifies the maximum numeric value that this field can have.

Example:

// +kubebuilder:validation:Maximum=100
Percentage int32
// +kubebuilder:validation:items:MaxProperties
int
for array items restricts the number of keys in an object

Example:

// +kubebuilder:validation:MaxProperties=10
Labels map[string]string
int
// +kubebuilder:validation:items:MaxProperties
int
for array items restricts the number of keys in an object

Example:

// +kubebuilder:validation:MaxProperties=10
Labels map[string]string
int
// +kubebuilder:validation:items:MaxLength
int
for array items specifies the maximum length for this string.

Example:

// +kubebuilder:validation:MaxLength=64
Name string
int
// +kubebuilder:validation:items:MaxLength
int
for array items specifies the maximum length for this string.

Example:

// +kubebuilder:validation:MaxLength=64
Name string
int
// +kubebuilder:validation:items:MaxItems
int
for array items specifies the maximum length for this list.

Example:

// +kubebuilder:validation:MaxItems=10
Items []string
int
// +kubebuilder:validation:items:MaxItems
int
for array items specifies the maximum length for this list.

Example:

// +kubebuilder:validation:MaxItems=10
Items []string
int
// +kubebuilder:validation:items:Format
string
for array items specifies additional "complex" formatting for this field.

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

Common formats include: "int32", "int64", "float", "double", "byte", "date", "date-time", "password".

Example:

// +kubebuilder:validation:Format=date-time
CreatedAt string
string
// +kubebuilder:validation:items:Format
string
for array items specifies additional "complex" formatting for this field.

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

Common formats include: "int32", "int64", "float", "double", "byte", "date", "date-time", "password".

Example:

// +kubebuilder:validation:Format=date-time
CreatedAt string
string
// +kubebuilder:validation:items:ExclusiveMinimum
bool
for array items indicates that the minimum is "up to" but not including that value.

Example (value must be greater than 0, not greater than or equal to 0):

// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:ExclusiveMinimum=true
PositiveNumber float64
bool
// +kubebuilder:validation:items:ExclusiveMinimum
bool
for array items indicates that the minimum is "up to" but not including that value.

Example (value must be greater than 0, not greater than or equal to 0):

// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:ExclusiveMinimum=true
PositiveNumber float64
bool
// +kubebuilder:validation:items:ExclusiveMaximum
bool
for array items indicates that the maximum is "up to" but not including that value.

Example (value must be less than 100, not less than or equal to 100):

// +kubebuilder:validation:Maximum=100
// +kubebuilder:validation:ExclusiveMaximum=true
Percentage float64
bool
// +kubebuilder:validation:items:ExclusiveMaximum
bool
for array items indicates that the maximum is "up to" but not including that value.

Example (value must be less than 100, not less than or equal to 100):

// +kubebuilder:validation:Maximum=100
// +kubebuilder:validation:ExclusiveMaximum=true
Percentage float64
bool
// +kubebuilder:validation:items:Enum
any
for array items specifies that this (scalar) field is restricted to the *exact* values specified here.

Example:

// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
ServiceType string
any
// +kubebuilder:validation:items:Enum
any
for array items specifies that this (scalar) field is restricted to the *exact* values specified here.

Example:

// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
ServiceType string
any
// +kubebuilder:validation:XValidation
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
marks a field as requiring a value for which a given

expression evaluates to true.

This marker may be repeated to specify multiple expressions, all of which must evaluate to true.

Examples:

// Basic field validation
// +kubebuilder:validation:XValidation:rule="self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas",message="replicas must be between minReplicas and maxReplicas"

// Validation with custom reason
// +kubebuilder:validation:XValidation:rule="self.x <= self.maxX",message="x cannot be greater than maxX",reason="FieldValueInvalid"

// Immutability check
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
// +kubebuilder:validation:XValidation
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
marks a field as requiring a value for which a given

expression evaluates to true.

This marker may be repeated to specify multiple expressions, all of which must evaluate to true.

Examples:

// Basic field validation
// +kubebuilder:validation:XValidation:rule="self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas",message="replicas must be between minReplicas and maxReplicas"

// Validation with custom reason
// +kubebuilder:validation:XValidation:rule="self.x <= self.maxX",message="x cannot be greater than maxX",reason="FieldValueInvalid"

// Immutability check
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
fieldPath
string
message
string
messageExpression
string
optionalOldSelf
bool
reason
string
rule
string
// +kubebuilder:validation:XIntOrString
marks a fields as an IntOrString.

This is required when applying patterns or other validations to an IntOrString field. Known information about the type is applied during the collapse phase and as such is not normally available during marker application.

Example:

// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^(\\d+|\\d+%|)$"
Port intstr.IntOrString
// +kubebuilder:validation:XIntOrString
marks a fields as an IntOrString.

This is required when applying patterns or other validations to an IntOrString field. Known information about the type is applied during the collapse phase and as such is not normally available during marker application.

Example:

// +kubebuilder:validation:XIntOrString
// +kubebuilder:validation:Pattern="^(\\d+|\\d+%|)$"
Port intstr.IntOrString
// +kubebuilder:validation:XEmbeddedResource
marks a fields as an embedded resource with apiVersion, kind and metadata fields.

An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.

Example:

// +kubebuilder:validation:EmbeddedResource
Template runtime.RawExtension
// +kubebuilder:validation:XEmbeddedResource
marks a fields as an embedded resource with apiVersion, kind and metadata fields.

An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.

Example:

// +kubebuilder:validation:EmbeddedResource
Template runtime.RawExtension
// +kubebuilder:validation:UniqueItems
bool
specifies that all items in this list must be unique.

Example:

// +kubebuilder:validation:UniqueItems=true
Tags []string
bool
// +kubebuilder:validation:UniqueItems
bool
specifies that all items in this list must be unique.

Example:

// +kubebuilder:validation:UniqueItems=true
Tags []string
bool
// +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".

Common types include: "string", "number", "integer", "boolean", "array", "object".

Example:

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
Time metav1.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".

Common types include: "string", "number", "integer", "boolean", "array", "object".

Example:

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
Time metav1.Time
string
// +kubebuilder:validation:Schemaless
marks a field as being a schemaless object.

Schemaless objects are not introspected, so you must provide any type and validation information yourself. One use for this tag is for embedding fields that hold JSONSchema typed objects. Because this field disables all type checking, it is recommended to be used only as a last resort.

Example:

// +kubebuilder:validation:Schemaless
JSONSchema apiextensionsv1.JSONSchemaProps
// +kubebuilder:validation:Required
specifies that all fields in this package are required by default.
// +kubebuilder:validation:Required
specifies that this field is required.
// +kubebuilder:validation:Pattern
string
specifies that this string must match the given regular expression.

Example (DNS subdomain):

// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
DNSName string
string
// +kubebuilder:validation:Pattern
string
specifies that this string must match the given regular expression.

Example (DNS subdomain):

// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
DNSName string
string
// +kubebuilder:validation:Optional
specifies that all fields in this package are optional by default.
// +kubebuilder:validation:Optional
specifies that this field is optional.
// +kubebuilder:validation:MultipleOf
specifies that this field must have a numeric value that's a multiple of this one.

Example (value must be a multiple of 5):

// +kubebuilder:validation:MultipleOf=5
Count int32
// +kubebuilder:validation:MultipleOf
specifies that this field must have a numeric value that's a multiple of this one.

Example (value must be a multiple of 5):

// +kubebuilder:validation:MultipleOf=5
Count int32
// +kubebuilder:validation:Minimum
specifies the minimum numeric value that this field can have. Negative numbers are supported.

Example:

// +kubebuilder:validation:Minimum=0
Replicas int32
// +kubebuilder:validation:Minimum
specifies the minimum numeric value that this field can have. Negative numbers are supported.

Example:

// +kubebuilder:validation:Minimum=0
Replicas int32
// +kubebuilder:validation:MinProperties
int
restricts the number of keys in an object

Example:

// +kubebuilder:validation:MinProperties=1
Metadata map[string]string
int
// +kubebuilder:validation:MinProperties
int
restricts the number of keys in an object

Example:

// +kubebuilder:validation:MinProperties=1
Metadata map[string]string
int
// +kubebuilder:validation:MinLength
int
specifies the minimum length for this string.

Example:

// +kubebuilder:validation:MinLength=1
Name string
int
// +kubebuilder:validation:MinLength
int
specifies the minimum length for this string.

Example:

// +kubebuilder:validation:MinLength=1
Name string
int
// +kubebuilder:validation:MinItems
int
specifies the minimum length for this list.

Example:

// +kubebuilder:validation:MinItems=1
Endpoints []string
int
// +kubebuilder:validation:MinItems
int
specifies the minimum length for this list.

Example:

// +kubebuilder:validation:MinItems=1
Endpoints []string
int
// +kubebuilder:validation:Maximum
specifies the maximum numeric value that this field can have.

Example:

// +kubebuilder:validation:Maximum=100
Percentage int32
// +kubebuilder:validation:Maximum
specifies the maximum numeric value that this field can have.

Example:

// +kubebuilder:validation:Maximum=100
Percentage int32
// +kubebuilder:validation:MaxProperties
int
restricts the number of keys in an object

Example:

// +kubebuilder:validation:MaxProperties=10
Labels map[string]string
int
// +kubebuilder:validation:MaxProperties
int
restricts the number of keys in an object

Example:

// +kubebuilder:validation:MaxProperties=10
Labels map[string]string
int
// +kubebuilder:validation:MaxLength
int
specifies the maximum length for this string.

Example:

// +kubebuilder:validation:MaxLength=64
Name string
int
// +kubebuilder:validation:MaxLength
int
specifies the maximum length for this string.

Example:

// +kubebuilder:validation:MaxLength=64
Name string
int
// +kubebuilder:validation:MaxItems
int
specifies the maximum length for this list.

Example:

// +kubebuilder:validation:MaxItems=10
Items []string
int
// +kubebuilder:validation:MaxItems
int
specifies the maximum length for this list.

Example:

// +kubebuilder:validation:MaxItems=10
Items []string
int
// +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".

Common formats include: "int32", "int64", "float", "double", "byte", "date", "date-time", "password".

Example:

// +kubebuilder:validation:Format=date-time
CreatedAt string
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".

Common formats include: "int32", "int64", "float", "double", "byte", "date", "date-time", "password".

Example:

// +kubebuilder:validation:Format=date-time
CreatedAt string
string
// +kubebuilder:validation:ExclusiveMinimum
bool
indicates that the minimum is "up to" but not including that value.

Example (value must be greater than 0, not greater than or equal to 0):

// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:ExclusiveMinimum=true
PositiveNumber float64
bool
// +kubebuilder:validation:ExclusiveMinimum
bool
indicates that the minimum is "up to" but not including that value.

Example (value must be greater than 0, not greater than or equal to 0):

// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:ExclusiveMinimum=true
PositiveNumber float64
bool
// +kubebuilder:validation:ExclusiveMaximum
bool
indicates that the maximum is "up to" but not including that value.

Example (value must be less than 100, not less than or equal to 100):

// +kubebuilder:validation:Maximum=100
// +kubebuilder:validation:ExclusiveMaximum=true
Percentage float64
bool
// +kubebuilder:validation:ExclusiveMaximum
bool
indicates that the maximum is "up to" but not including that value.

Example (value must be less than 100, not less than or equal to 100):

// +kubebuilder:validation:Maximum=100
// +kubebuilder:validation:ExclusiveMaximum=true
Percentage float64
bool
// +kubebuilder:validation:ExactlyOneOf
string
specifies a list of field names that must conform to the ExactlyOneOf constraint.
string
// +kubebuilder:validation:Enum
any
specifies that this (scalar) field is restricted to the *exact* values specified here.

Example:

// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
ServiceType string
any
// +kubebuilder:validation:Enum
any
specifies that this (scalar) field is restricted to the *exact* values specified here.

Example:

// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
ServiceType string
any
// +kubebuilder:validation:EmbeddedResource
marks a fields as an embedded resource with apiVersion, kind and metadata fields.

An embedded resource is a value that has apiVersion, kind and metadata fields. They are validated implicitly according to the semantics of the currently running apiserver. It is not necessary to add any additional schema for these field, yet it is possible. This can be combined with PreserveUnknownFields.

Example:

// +kubebuilder:validation:EmbeddedResource
Template runtime.RawExtension
// +kubebuilder:validation:AtMostOneOf
string
specifies a list of field names that must conform to the AtMostOneOf constraint.
string
// +kubebuilder:validation:AtLeastOneOf
string
specifies a list of field names that must conform to the AtLeastOneOf constraint.
string
// +kubebuilder:title
any
sets the title for this field.

The title is metadata that makes the OpenAPI documentation more user-friendly, making the schema more understandable when viewed in documentation tools. It's a metadata field that doesn't affect validation but provides important context about what the schema represents.

Examples:

// Simple title
// +kubebuilder:title="Replica Count"
Replicas int32

// Descriptive title
// +kubebuilder:title="Database Connection Configuration"
DatabaseConfig DatabaseConfig
any
is the title text to be shown in OpenAPI documentation.
// +kubebuilder:title
any
sets the title for this field.

The title is metadata that makes the OpenAPI documentation more user-friendly, making the schema more understandable when viewed in documentation tools. It's a metadata field that doesn't affect validation but provides important context about what the schema represents.

Examples:

// Simple title
// +kubebuilder:title="Replica Count"
Replicas int32

// Descriptive title
// +kubebuilder:title="Database Connection Configuration"
DatabaseConfig DatabaseConfig
any
is the title text to be shown in OpenAPI documentation.
// +kubebuilder:example
any
sets the example value for this field.

An example value will be accepted as any value valid for the field. Formatting for common types include: boolean: true, string: Cluster, numerical: 1.24, array: {1,2}, object: {policy: "delete"}). Examples should be defined in pruned form, and only best-effort validation will be performed. Full validation of an example requires submission of the containing CRD to an apiserver.

Examples are shown in API documentation to help users understand the expected format.

Usage Examples:

// String example
// +kubebuilder:example="my-service"
ServiceName string

// Integer example
// +kubebuilder:example=5
Replicas int32

// Boolean example
// +kubebuilder:example=false
Debug bool

// Array example
// +kubebuilder:example={8080,8443}
Ports []int

// Object example
// +kubebuilder:example={cpu: "100m", memory: "128Mi"}
Resources map[string]string
any
is the example value to be shown in API documentation.
// +kubebuilder:default
any
sets the default value for this field.

A default value will be accepted as any value valid for the field. Formatting for common types include: boolean: true, string: Cluster, numerical: 1.24, array: {1,2}, object: {policy: "delete"}). Defaults should be defined in pruned form, and only best-effort validation will be performed. Full validation of a default requires submission of the containing CRD to an apiserver.

Examples:

// String default
// +kubebuilder:default="ClusterIP"
ServiceType string

// Integer default
// +kubebuilder:default=3
Replicas int32

// Boolean default
// +kubebuilder:default=true
Enabled bool

// Array default
// +kubebuilder:default={80,443}
Ports []int

// Object default
// +kubebuilder:default={replicas: 1}
Config map[string]interface{}
any
is the default value. It can be any value valid for the field type.
// +k8s:required
specifies that this field is required.
// +k8s:optional
specifies that this field is optional.
// +k8s:immutable
marks a field as immutable. Once set, the value cannot be changed.

For optional fields, a single transition from unset to set is allowed.

Note that immutable fields that are nested below optional fields can still be updated by unsetting the optional parent field and re-setting it again.

Examples:

// +k8s:immutable
// +required
Port intstr.IntOrString

// +k8s:immutable
// +optional
TargetPort intstr.IntOrString
// +default
value
any
sets the default value for this field.

A default value will be accepted as any value valid for the field. Only JSON-formatted values are accepted. ref(...) values are ignored. Formatting for common types include: boolean: true, string: "Cluster", numerical: 1.24, array: [1,2], object: {"policy": "delete"}). Defaults should be defined in pruned form, and only best-effort validation will be performed. Full validation of a default requires submission of the containing CRD to an apiserver.

Examples:

// String default (note the JSON quotes)
// +default="ClusterIP"
ServiceType string

// Integer default
// +default=3
Replicas int32

// Boolean default
// +default=true
Enabled bool

// Array default (JSON format)
// +default=[80,443]
Ports []int

// Object default (JSON format)
// +default={"policy": "delete"}
Config map[string]interface{}
value
any
is the default value in JSON format. It can be any value valid for the field type.