validation

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 97

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, options ...ValidationOption) 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, options ...ValidationOption) 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{}, options ...ValidationOption) *validate.Result

func (*RatchetingSchemaValidator) ValidateUpdate added in v0.28.0

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

type SchemaCreateValidator added in v0.28.0

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

type SchemaValidator added in v0.28.0

type SchemaValidator interface {
	SchemaCreateValidator
	ValidateUpdate(new, old interface{}, options ...ValidationOption) *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.

func NewSchemaValidatorFromOpenAPI added in v0.29.0

func NewSchemaValidatorFromOpenAPI(openapiSchema *spec.Schema) SchemaValidator

type ValidationMetrics added in v0.29.0

type ValidationMetrics interface {
	ObserveRatchetingTime(d time.Duration)
}

Interface to stub for tests

var Metrics ValidationMetrics = &validationMetrics{
	RatchetingTime: metrics.NewHistogram(&metrics.HistogramOpts{
		Namespace:      namespace,
		Subsystem:      subsystem,
		Name:           "ratcheting_seconds",
		Help:           "Time for comparison of old to new for the purposes of CRDValidationRatcheting during an UPDATE in seconds.",
		StabilityLevel: metrics.ALPHA,

		Buckets: metrics.ExponentialBuckets(0.00001, 4, 10),
	}),
}

type ValidationOption added in v0.29.0

type ValidationOption func(*ValidationOptions)

func WithRatcheting added in v0.29.0

func WithRatcheting(correlation *common.CorrelatedObject) ValidationOption

type ValidationOptions added in v0.29.0

type ValidationOptions struct {
	// Whether errors from unchanged portions of the schema should be ratcheted
	// This field is ignored for Validate
	Ratcheting bool

	// Correlation between old and new arguments.
	// If set, this is expected to be the correlation between the `new` and
	// `old` arguments to ValidateUpdate, and values for `new` and `old` will
	// be taken from the correlation.
	//
	// This field is ignored for Validate
	//
	// Used for ratcheting, but left as a separate field since it may be used
	// for other purposes in the future.
	CorrelatedObject *common.CorrelatedObject
}

func NewValidationOptions added in v0.29.0

func NewValidationOptions(opts ...ValidationOption) ValidationOptions

Jump to

Keyboard shortcuts

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