validation

package
v0.28.14 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 138

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertJSONSchemaProps

func ConvertJSONSchemaProps(in *apiextensions.JSONSchemaProps, out *spec.Schema) error

ConvertJSONSchemaProps converts the schema from apiextensions.JSONSchemaPropos to go-openapi/spec.Schema.

func ConvertJSONSchemaPropsWithPostProcess

func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, out *spec.Schema, postProcess PostProcessFunc) error

ConvertJSONSchemaPropsWithPostProcess converts the schema from apiextensions.JSONSchemaPropos to go-openapi/spec.Schema and run a post process step on each JSONSchemaProps node. postProcess is never called for nil schemas.

func StripUnsupportedFormatsPostProcess added in v0.17.0

func StripUnsupportedFormatsPostProcess(s *spec.Schema) error

StripUnsupportedFormatsPostProcess sets unsupported formats to empty string.

func ValidateCustomResource

func ValidateCustomResource(fldPath *field.Path, customResource interface{}, validator SchemaCreateValidator) field.ErrorList

ValidateCustomResource validates the Custom Resource against the schema in the CustomResourceDefinition. CustomResource is a JSON data structure.

func ValidateCustomResourceUpdate added in v0.28.0

func ValidateCustomResourceUpdate(fldPath *field.Path, customResource, old interface{}, validator SchemaValidator) field.ErrorList

ValidateCustomResourceUpdate validates the transition of Custom Resource from `old` to `new` against the schema in the CustomResourceDefinition. Both customResource and old represent a JSON data structures.

If feature `CRDValidationRatcheting` is disabled, this behaves identically to ValidateCustomResource(customResource).

Types

type PostProcessFunc

type PostProcessFunc func(*spec.Schema) error

PostProcessFunc post-processes one node of a spec.Schema.

type RatchetingSchemaValidator added in v0.28.0

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

RatchetingSchemaValidator wraps kube-openapis SchemaValidator to provide a ValidateUpdate function which allows ratcheting

func NewRatchetingSchemaValidator added in v0.28.0

func NewRatchetingSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry, options ...validate.Option) *RatchetingSchemaValidator

func (*RatchetingSchemaValidator) Validate added in v0.28.0

func (r *RatchetingSchemaValidator) Validate(new interface{}) *validate.Result

func (*RatchetingSchemaValidator) ValidateUpdate added in v0.28.0

func (r *RatchetingSchemaValidator) ValidateUpdate(new, old interface{}) *validate.Result

type SchemaCreateValidator added in v0.28.0

type SchemaCreateValidator interface {
	Validate(value interface{}) *validate.Result
}

type SchemaValidator added in v0.28.0

type SchemaValidator interface {
	SchemaCreateValidator
	ValidateUpdate(new, old interface{}) *validate.Result
}

func NewSchemaValidator

func NewSchemaValidator(customResourceValidation *apiextensions.JSONSchemaProps) (SchemaValidator, *spec.Schema, error)

NewSchemaValidator creates an openapi schema validator for the given CRD validation.

If feature `CRDValidationRatcheting` is disabled, this returns validator which validates all `Update`s and `Create`s as a `Create` - without considering old value.

If feature `CRDValidationRatcheting` is enabled - the validator returned will support ratcheting unchanged correlatable fields across an update.

Jump to

Keyboard shortcuts

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