markers

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Kubebuilder marker used in comments
	Kubebuilder = "+kubebuilder:"

	FieldRequired = "required"
	FieldOptional = "optional"
)

Variables

View Source
var AllDefinitions []*definitionWithHelp

AllDefinitions contains all marker definitions for this package.

View Source
var FieldOnlyMarkers = []*definitionWithHelp{
	must(markers.MakeDefinition("kubebuilder:validation:Required", markers.DescribesField, Required{})).
		WithHelp(markers.SimpleHelp("CRD validation", "specifies that this field is required, if fields are optional by default.")),

	must(markers.MakeDefinition("kubebuilder:validation:Nullable", markers.DescribesField, Nullable{})),

	must(markers.MakeAnyTypeDefinition("kubebuilder:default", markers.DescribesField, Default{})),

	must(markers.MakeAnyTypeDefinition("kubebuilder:example", markers.DescribesField, Example{})),

	must(markers.MakeDefinition("kubebuilder:validation:EmbeddedResource", markers.DescribesField, XEmbeddedResource{})),

	must(markers.MakeDefinition("kubebuilder:validation:Schemaless", markers.DescribesField, Schemaless{})),
}

FieldOnlyMarkers list field-specific validation markers (i.e. those markers that don't make sense on a type, and thus aren't in ValidationMarkers).

View Source
var ValidationIshMarkers = []*definitionWithHelp{
	must(markers.MakeDefinition("kubebuilder:pruning:PreserveUnknownFields", markers.DescribesField, XPreserveUnknownFields{})),
	must(markers.MakeDefinition("kubebuilder:pruning:PreserveUnknownFields", markers.DescribesType, XPreserveUnknownFields{})),
}

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.

View Source
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

func Register

func Register(reg *markers.Registry) error

Register registers all definitions for CRD generation to the given registry.

Types

type Default added in v0.2.2

type Default struct {
	Value interface{}
}

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 added in v0.2.2

func (m Default) ApplyToSchema(o *openapi3.Schema)

type Enum added in v0.2.2

type Enum []interface{}

Enum specifies that this (scalar) field is restricted to the *exact* values specified here.

func (Enum) ApplyToSchema added in v0.2.2

func (m Enum) ApplyToSchema(o *openapi3.Schema)

type Example added in v0.2.2

type Example struct {
	Value interface{}
}

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 added in v0.2.2

func (m Example) ApplyToSchema(o *openapi3.Schema)

type ExclusiveMaximum added in v0.2.2

type ExclusiveMaximum bool

ExclusiveMaximum indicates that the maximum is "up to" but not including that value.

func (ExclusiveMaximum) ApplyToSchema added in v0.2.2

func (m ExclusiveMaximum) ApplyToSchema(o *openapi3.Schema)

type ExclusiveMinimum added in v0.2.2

type ExclusiveMinimum bool

ExclusiveMinimum indicates that the minimum is "up to" but not including that value.

func (ExclusiveMinimum) ApplyToSchema added in v0.2.2

func (m ExclusiveMinimum) ApplyToSchema(o *openapi3.Schema)

type Format added in v0.2.2

type Format string

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 added in v0.2.2

func (m Format) ApplyToSchema(o *openapi3.Schema)

type MaxItems added in v0.2.2

type MaxItems int

MaxItems specifies the maximum length for this list.

func (MaxItems) ApplyToSchema added in v0.2.2

func (m MaxItems) ApplyToSchema(o *openapi3.Schema)

type MaxLength added in v0.2.2

type MaxLength int

MaxLength specifies the maximum length for this string.

func (MaxLength) ApplyToSchema added in v0.2.2

func (m MaxLength) ApplyToSchema(o *openapi3.Schema)

type MaxProperties added in v0.2.2

type MaxProperties int

MaxProperties restricts the number of keys in an object

func (MaxProperties) ApplyToSchema added in v0.2.2

func (m MaxProperties) ApplyToSchema(o *openapi3.Schema)

type Maximum added in v0.2.2

type Maximum float64

Maximum specifies the maximum numeric value that this field can have.

func (Maximum) ApplyToSchema added in v0.2.2

func (m Maximum) ApplyToSchema(o *openapi3.Schema)

func (Maximum) Value added in v0.2.2

func (m Maximum) Value() float64

type MinItems added in v0.2.2

type MinItems int

MinItems specifies the minimum length for this list.

func (MinItems) ApplyToSchema added in v0.2.2

func (m MinItems) ApplyToSchema(o *openapi3.Schema)

type MinLength added in v0.2.2

type MinLength int

MinLength specifies the minimum length for this string.

func (MinLength) ApplyToSchema added in v0.2.2

func (m MinLength) ApplyToSchema(o *openapi3.Schema)

type MinProperties added in v0.2.2

type MinProperties int

MinProperties restricts the number of keys in an object

func (MinProperties) ApplyToSchema added in v0.2.2

func (m MinProperties) ApplyToSchema(o *openapi3.Schema)

type Minimum added in v0.2.2

type Minimum float64

Minimum specifies the minimum numeric value that this field can have. Negative numbers are supported.

func (Minimum) ApplyToSchema added in v0.2.2

func (m Minimum) ApplyToSchema(o *openapi3.Schema)

func (Minimum) Value added in v0.2.2

func (m Minimum) Value() float64

type MultipleOf added in v0.2.2

type MultipleOf float64

MultipleOf specifies that this field must have a numeric value that's a multiple of this one.

func (MultipleOf) ApplyToSchema added in v0.2.2

func (m MultipleOf) ApplyToSchema(o *openapi3.Schema)

func (MultipleOf) Value added in v0.2.2

func (m MultipleOf) Value() float64

type Nullable added in v0.2.2

type Nullable struct{}

Nullable marks this field as allowing the "null" value.

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

func (Nullable) ApplyToSchema added in v0.2.2

func (m Nullable) ApplyToSchema(o *openapi3.Schema)

type Pattern added in v0.2.2

type Pattern string

Pattern specifies that this string must match the given regular expression.

func (Pattern) ApplyToSchema added in v0.2.2

func (m Pattern) ApplyToSchema(o *openapi3.Schema)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() (*Registry, error)

func (*Registry) ApplyRulesToSchema

func (r *Registry) ApplyRulesToSchema(
	rules []string,
	o *openapi3.Schema,
	target markers.TargetType,
) error

func (*Registry) GetSchemaType

func (r *Registry) GetSchemaType(
	rules []string,
	target markers.TargetType,
) Type

func (*Registry) IsRequired added in v0.2.2

func (r *Registry) IsRequired(
	rules []string,
) bool

func (*Registry) MustApplyRulesToSchema

func (r *Registry) MustApplyRulesToSchema(
	rules []string,
	o *openapi3.Schema,
	target markers.TargetType,
)

type Required added in v0.2.2

type Required struct{}

Required marks a field as required.

func (Required) ApplyToSchema added in v0.2.2

func (m Required) ApplyToSchema(o *openapi3.Schema)

type SchemaMarker

type SchemaMarker interface {
	ApplyToSchema(o *openapi3.Schema)
}

type Schemaless added in v0.2.2

type Schemaless struct{}

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) ApplyToSchema added in v0.2.2

func (m Schemaless) ApplyToSchema(o *openapi3.Schema)

type Type

type Type string

Type is a marker that specifies the type of a field in the schema It only supports the following types: - object: an opaque object - value: an opauqe value

const (
	TypeObject Type = "object"
	TypeValue  Type = "value"
)

func (Type) ApplyToSchema

func (m Type) ApplyToSchema(o *openapi3.Schema)

type UniqueItems added in v0.2.2

type UniqueItems bool

UniqueItems specifies that all items in this list must be unique.

func (UniqueItems) ApplyToSchema added in v0.2.2

func (m UniqueItems) ApplyToSchema(o *openapi3.Schema)

type XEmbeddedResource added in v0.2.2

type XEmbeddedResource struct{}

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 added in v0.2.2

func (m XEmbeddedResource) ApplyToSchema(o *openapi3.Schema)

type XIntOrString added in v0.2.2

type XIntOrString struct{}

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) ApplyToSchema added in v0.2.2

func (m XIntOrString) ApplyToSchema(o *openapi3.Schema)

type XPreserveUnknownFields added in v0.2.2

type XPreserveUnknownFields struct{}

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.

Note: The kubebuilder:validation:XPreserveUnknownFields variant is deprecated in favor of the kubebuilder:pruning:PreserveUnknownFields variant. They function identically.

func (XPreserveUnknownFields) ApplyToSchema added in v0.2.2

func (m XPreserveUnknownFields) ApplyToSchema(o *openapi3.Schema)

type XValidation

type XValidation struct {
	Rule              string `json:"rule"`
	Message           string `marker:",optional" json:"message,omitempty"`
	MessageExpression string `marker:",optional" json:"messageExpression,omitempty"`
}

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 (x XValidation) ApplyToSchema(o *openapi3.Schema)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL