Documentation ¶
Index ¶
- Constants
- Variables
- func Register(ctx context.Context) error
- type Default
- type Enum
- type Example
- type ExclusiveMaximum
- type ExclusiveMinimum
- type Format
- type ListMapKey
- type ListType
- type MapType
- type MaxItems
- type MaxLength
- type MaxProperties
- type Maximum
- type MinItems
- type MinLength
- type MinProperties
- type Minimum
- type MultipleOf
- type Nullable
- type Pattern
- type Schemaless
- type StructType
- type Type
- type UniqueItems
- type XEmbeddedResource
- type XIntOrString
- type XPreserveUnknownFields
- type XValidation
Constants ¶
const (
SchemalessName = "kubebuilder:validation:Schemaless"
)
Variables ¶
var AllDefinitions []*definitionWithHelp
AllDefinitions contains all marker definitions for this package.
var FieldOnlyMarkers = []*definitionWithHelp{ must(markers.MakeDefinition("kubebuilder:validation:Required", markers.DescribesField, struct{}{})). WithHelp(markers.SimpleHelp("CRD validation", "specifies that this field is required, if fields are optional by default.")), must(markers.MakeDefinition("kubebuilder:validation:Optional", markers.DescribesField, struct{}{})). WithHelp(markers.SimpleHelp("CRD validation", "specifies that this field is optional, if fields are required by default.")), must(markers.MakeDefinition("optional", markers.DescribesField, struct{}{})). WithHelp(markers.SimpleHelp("CRD validation", "specifies that this field is optional, if fields are required by default.")), must(markers.MakeDefinition("nullable", markers.DescribesField, Nullable{})). WithHelp(Nullable{}.Help()), must(markers.MakeAnyTypeDefinition("kubebuilder:default", markers.DescribesField, Default{})). WithHelp(Default{}.Help()), must(markers.MakeAnyTypeDefinition("kubebuilder:example", markers.DescribesField, Example{})). WithHelp(Example{}.Help()), must(markers.MakeDefinition("kubebuilder:validation:EmbeddedResource", markers.DescribesField, XEmbeddedResource{})). WithHelp(XEmbeddedResource{}.Help()), must(markers.MakeDefinition(SchemalessName, markers.DescribesField, Schemaless{})). WithHelp(Schemaless{}.Help()), }
FieldOnlyMarkers list field-specific validation markers (i.e. those markers that don't make sense on a type, and thus aren't in ValidationMarkers).
var TopologyMarkers = []*definitionWithHelp{ must(markers.MakeDefinition("listMapKey", markers.DescribesField, ListMapKey(""))). WithHelp(ListMapKey("").Help()), must(markers.MakeDefinition("listMapKey", markers.DescribesType, ListMapKey(""))). WithHelp(ListMapKey("").Help()), must(markers.MakeDefinition("listType", markers.DescribesField, ListType(""))). WithHelp(ListType("").Help()), must(markers.MakeDefinition("listType", markers.DescribesType, ListType(""))). WithHelp(ListType("").Help()), must(markers.MakeDefinition("mapType", markers.DescribesField, MapType(""))). WithHelp(MapType("").Help()), must(markers.MakeDefinition("mapType", markers.DescribesType, MapType(""))). WithHelp(MapType("").Help()), must(markers.MakeDefinition("structType", markers.DescribesField, StructType(""))). WithHelp(StructType("").Help()), must(markers.MakeDefinition("structType", markers.DescribesType, StructType(""))). WithHelp(StructType("").Help()), }
TopologyMarkers specify topology markers (i.e. markers that describe if a list behaves as an associative-list or a set, if a map is atomic or not).
var ValidationIshMarkers = []*definitionWithHelp{ must(markers.MakeDefinition("kubebuilder:pruning:PreserveUnknownFields", markers.DescribesField, XPreserveUnknownFields{})). WithHelp(XPreserveUnknownFields{}.Help()), must(markers.MakeDefinition("kubebuilder:pruning:PreserveUnknownFields", markers.DescribesType, XPreserveUnknownFields{})). WithHelp(XPreserveUnknownFields{}.Help()), }
ValidationIshMarkers are field-and-type markers that don't fall under the :validation: prefix, and/or don't have a name that directly matches their type.
var ValidationMarkers = mustMakeAllWithPrefix("kubebuilder:validation", markers.DescribesField, Maximum(0), Minimum(0), ExclusiveMaximum(false), ExclusiveMinimum(false), MultipleOf(0), MinProperties(0), MaxProperties(0), MaxLength(0), MinLength(0), Pattern(""), MaxItems(0), MinItems(0), UniqueItems(false), Enum(nil), Format(""), Type(""), XPreserveUnknownFields{}, XEmbeddedResource{}, XIntOrString{}, XValidation{}, )
ValidationMarkers lists all available markers that affect CRD schema generation, except for the few that don't make sense as type-level markers (see FieldOnlyMarkers). All markers start with `+kubebuilder:validation:`, and continue with their type name. A copy is produced of all markers that describes types as well, for making types reusable and writing complex validations on slice items.
Functions ¶
Types ¶
type Default ¶
type Default struct {
Value interface{}
}
+controllertools:marker:generateHelp:category="CRD validation" Default 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.
func (Default) ApplyToSchema ¶
func (m Default) ApplyToSchema(schema *apiext.JSONSchemaProps) error
Defaults are only valid CRDs created with the v1 API
func (Default) Help ¶
func (Default) Help() *markers.DefinitionHelp
type Enum ¶
type Enum []interface{}
+controllertools:marker:generateHelp:category="CRD validation" Enum specifies that this (scalar) field is restricted to the *exact* values specified here.
func (Enum) ApplyToSchema ¶
func (m Enum) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Enum) Help ¶
func (Enum) Help() *markers.DefinitionHelp
type Example ¶
type Example struct {
Value interface{}
}
+controllertools:marker:generateHelp:category="CRD validation" Example 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.
func (Example) ApplyToSchema ¶
func (m Example) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Example) Help ¶
func (Example) Help() *markers.DefinitionHelp
type ExclusiveMaximum ¶
type ExclusiveMaximum bool
+controllertools:marker:generateHelp:category="CRD validation" ExclusiveMaximum indicates that the maximum is "up to" but not including that value.
func (ExclusiveMaximum) ApplyToSchema ¶
func (m ExclusiveMaximum) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (ExclusiveMaximum) Help ¶
func (ExclusiveMaximum) Help() *markers.DefinitionHelp
type ExclusiveMinimum ¶
type ExclusiveMinimum bool
+controllertools:marker:generateHelp:category="CRD validation" ExclusiveMinimum indicates that the minimum is "up to" but not including that value.
func (ExclusiveMinimum) ApplyToSchema ¶
func (m ExclusiveMinimum) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (ExclusiveMinimum) Help ¶
func (ExclusiveMinimum) Help() *markers.DefinitionHelp
type Format ¶
type Format string
+controllertools:marker:generateHelp:category="CRD validation" Format specifies additional "complex" formatting for this field.
For example, a date-time field would be marked as "type: string" and "format: date-time".
func (Format) ApplyToSchema ¶
func (m Format) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Format) Help ¶
func (Format) Help() *markers.DefinitionHelp
type ListMapKey ¶
type ListMapKey string
ListMapKey specifies the keys to map listTypes.
It indicates the index of a map list. They can be repeated if multiple keys must be used. It can only be used when ListType is set to map, and the keys should be scalar types.
func (ListMapKey) ApplyToSchema ¶
func (l ListMapKey) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (ListMapKey) Help ¶
func (ListMapKey) Help() *markers.DefinitionHelp
type ListType ¶
type ListType string
ListType specifies the type of data-structure that the list represents (map, set, atomic).
Possible data-structure types of a list are:
"map": it needs to have a key field, which will be used to build an associative list. A typical example is a the pod container list, which is indexed by the container name.
"set": Fields need to be "scalar", and there can be only one occurrence of each.
"atomic": All the fields in the list are treated as a single value, are typically manipulated together by the same actor.
func (ListType) ApplyFirst ¶
func (l ListType) ApplyFirst()
func (ListType) ApplyToSchema ¶
func (l ListType) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (ListType) Help ¶
func (ListType) Help() *markers.DefinitionHelp
type MapType ¶
type MapType string
MapType specifies the level of atomicity of the map; i.e. whether each item in the map is independent of the others, or all fields are treated as a single unit.
Possible values:
"granular": items in the map are independent of each other, and can be manipulated by different actors. This is the default behavior.
"atomic": all fields are treated as one unit. Any changes have to replace the entire map.
func (MapType) ApplyToSchema ¶
func (m MapType) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MapType) Help ¶
func (MapType) Help() *markers.DefinitionHelp
type MaxItems ¶
type MaxItems int
+controllertools:marker:generateHelp:category="CRD validation" MaxItems specifies the maximum length for this list.
func (MaxItems) ApplyToSchema ¶
func (m MaxItems) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MaxItems) Help ¶
func (MaxItems) Help() *markers.DefinitionHelp
type MaxLength ¶
type MaxLength int
+controllertools:marker:generateHelp:category="CRD validation" MaxLength specifies the maximum length for this string.
func (MaxLength) ApplyToSchema ¶
func (m MaxLength) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MaxLength) Help ¶
func (MaxLength) Help() *markers.DefinitionHelp
type MaxProperties ¶
type MaxProperties int
+controllertools:marker:generateHelp:category="CRD validation" MaxProperties restricts the number of keys in an object
func (MaxProperties) ApplyToSchema ¶
func (m MaxProperties) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MaxProperties) Help ¶
func (MaxProperties) Help() *markers.DefinitionHelp
type Maximum ¶
type Maximum float64
+controllertools:marker:generateHelp:category="CRD validation" Maximum specifies the maximum numeric value that this field can have.
func (Maximum) ApplyToSchema ¶
func (m Maximum) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Maximum) Help ¶
func (Maximum) Help() *markers.DefinitionHelp
type MinItems ¶
type MinItems int
+controllertools:marker:generateHelp:category="CRD validation" MinItems specifies the minimum length for this list.
func (MinItems) ApplyToSchema ¶
func (m MinItems) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MinItems) Help ¶
func (MinItems) Help() *markers.DefinitionHelp
type MinLength ¶
type MinLength int
+controllertools:marker:generateHelp:category="CRD validation" MinLength specifies the minimum length for this string.
func (MinLength) ApplyToSchema ¶
func (m MinLength) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MinLength) Help ¶
func (MinLength) Help() *markers.DefinitionHelp
type MinProperties ¶
type MinProperties int
+controllertools:marker:generateHelp:category="CRD validation" MinProperties restricts the number of keys in an object
func (MinProperties) ApplyToSchema ¶
func (m MinProperties) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MinProperties) Help ¶
func (MinProperties) Help() *markers.DefinitionHelp
type Minimum ¶
type Minimum float64
+controllertools:marker:generateHelp:category="CRD validation" Minimum specifies the minimum numeric value that this field can have. Negative numbers are supported.
func (Minimum) ApplyToSchema ¶
func (m Minimum) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Minimum) Help ¶
func (Minimum) Help() *markers.DefinitionHelp
type MultipleOf ¶
type MultipleOf float64
+controllertools:marker:generateHelp:category="CRD validation" MultipleOf specifies that this field must have a numeric value that's a multiple of this one.
func (MultipleOf) ApplyToSchema ¶
func (m MultipleOf) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (MultipleOf) Help ¶
func (MultipleOf) Help() *markers.DefinitionHelp
func (MultipleOf) Value ¶
func (m MultipleOf) Value() float64
type Nullable ¶
type Nullable struct{}
+controllertools:marker:generateHelp:category="CRD validation" Nullable marks this field as allowing the "null" value.
This is often not necessary, but may be helpful with custom serialization.
func (Nullable) ApplyToSchema ¶
func (m Nullable) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Nullable) Help ¶
func (Nullable) Help() *markers.DefinitionHelp
type Pattern ¶
type Pattern string
+controllertools:marker:generateHelp:category="CRD validation" Pattern specifies that this string must match the given regular expression.
func (Pattern) ApplyToSchema ¶
func (m Pattern) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Pattern) Help ¶
func (Pattern) Help() *markers.DefinitionHelp
type Schemaless ¶
type Schemaless struct{}
+controllertools:marker:generateHelp:category="CRD 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.
func (Schemaless) Help ¶
func (Schemaless) Help() *markers.DefinitionHelp
type StructType ¶
type StructType string
StructType specifies the level of atomicity of the struct; i.e. whether each field in the struct is independent of the others, or all fields are treated as a single unit.
Possible values:
"granular": fields in the struct are independent of each other, and can be manipulated by different actors. This is the default behavior.
"atomic": all fields are treated as one unit. Any changes have to replace the entire struct.
func (StructType) ApplyToSchema ¶
func (s StructType) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (StructType) Help ¶
func (StructType) Help() *markers.DefinitionHelp
type Type ¶
type Type string
+controllertools:marker:generateHelp:category="CRD validation" Type 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".
func (Type) ApplyFirst ¶
func (m Type) ApplyFirst()
func (Type) ApplyToSchema ¶
func (m Type) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (Type) Help ¶
func (Type) Help() *markers.DefinitionHelp
type UniqueItems ¶
type UniqueItems bool
+controllertools:marker:generateHelp:category="CRD validation" UniqueItems specifies that all items in this list must be unique.
func (UniqueItems) ApplyToSchema ¶
func (m UniqueItems) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (UniqueItems) Help ¶
func (UniqueItems) Help() *markers.DefinitionHelp
type XEmbeddedResource ¶
type XEmbeddedResource struct{}
+controllertools:marker:generateHelp:category="CRD 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.
func (XEmbeddedResource) ApplyToSchema ¶
func (m XEmbeddedResource) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (XEmbeddedResource) Help ¶
func (XEmbeddedResource) Help() *markers.DefinitionHelp
type XIntOrString ¶
type XIntOrString struct{}
+controllertools:marker:generateHelp:category="CRD validation" IntOrString marks a fields as an IntOrString.
This is required when applying patterns or other validations to an IntOrString field. Knwon information about the type is applied during the collapse phase and as such is not normally available during marker application.
func (XIntOrString) ApplyFirst ¶
func (m XIntOrString) ApplyFirst()
func (XIntOrString) ApplyToSchema ¶
func (m XIntOrString) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (XIntOrString) Help ¶
func (XIntOrString) Help() *markers.DefinitionHelp
type XPreserveUnknownFields ¶
type XPreserveUnknownFields struct{}
+controllertools:marker:generateHelp:category="CRD processing" PreserveUnknownFields stops the apiserver from pruning fields which are not specified.
By default the apiserver drops unknown fields from the request payload during the decoding step. This marker stops the API server from doing so. It affects fields recursively, but switches back to normal pruning behaviour if nested properties or additionalProperties are specified in the schema. This can either be true or undefined. False is forbidden.
NB: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.
func (XPreserveUnknownFields) ApplyToSchema ¶
func (m XPreserveUnknownFields) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (XPreserveUnknownFields) Help ¶
func (XPreserveUnknownFields) Help() *markers.DefinitionHelp
type XValidation ¶
+controllertools:marker:generateHelp:category="CRD validation" XValidation 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.
func (XValidation) ApplyToSchema ¶
func (m XValidation) ApplyToSchema(schema *apiext.JSONSchemaProps) error
func (XValidation) Help ¶
func (XValidation) Help() *markers.DefinitionHelp