package validation
import "k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
Index ¶
- func ConvertJSONSchemaProps(in *apiextensions.JSONSchemaProps, out *spec.Schema) error
- func ConvertJSONSchemaPropsWithPostProcess(in *apiextensions.JSONSchemaProps, out *spec.Schema, postProcess PostProcessFunc) error
- func StripUnsupportedFormatsPostProcess(s *spec.Schema) error
- func StripUnsupportedFormatsPostProcessorForVersion(compatibilityVersion *version.Version) func(s *spec.Schema) error
- func ValidateCustomResource(fldPath *field.Path, customResource interface{}, validator SchemaCreateValidator, options ...ValidationOption) field.ErrorList
- func ValidateCustomResourceUpdate(fldPath *field.Path, customResource, old interface{}, validator SchemaValidator, options ...ValidationOption) field.ErrorList
- type PostProcessFunc
- type RatchetingSchemaValidator
- func NewRatchetingSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry, options ...validate.Option) *RatchetingSchemaValidator
- func (r *RatchetingSchemaValidator) Validate(new interface{}, options ...ValidationOption) *validate.Result
- func (r *RatchetingSchemaValidator) ValidateUpdate(new, old interface{}, options ...ValidationOption) *validate.Result
- type SchemaCreateValidator
- type SchemaValidator
- func NewSchemaValidator(customResourceValidation *apiextensions.JSONSchemaProps) (SchemaValidator, *spec.Schema, error)
- func NewSchemaValidatorFromOpenAPI(openapiSchema *spec.Schema) SchemaValidator
- type ValidationMetrics
- type ValidationOption
- type ValidationOptions
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 ¶
StripUnsupportedFormatsPostProcess sets unsupported formats to empty string. Only supports formats supported by all known version of Kubernetes. Deprecated: Use StripUnsupportedFormatsPostProcessorForVersion instead.
func StripUnsupportedFormatsPostProcessorForVersion ¶
func StripUnsupportedFormatsPostProcessorForVersion(compatibilityVersion *version.Version) func(s *spec.Schema) error
StripUnsupportedFormatsPostProcessorForVersion determines the supported formats at the given compatibility version and 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 ¶
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 ¶
PostProcessFunc post-processes one node of a spec.Schema.
type RatchetingSchemaValidator ¶
type RatchetingSchemaValidator struct {
// contains filtered or unexported fields
}
RatchetingSchemaValidator wraps kube-openapis SchemaValidator to provide a ValidateUpdate function which allows ratcheting
func NewRatchetingSchemaValidator ¶
func NewRatchetingSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry, options ...validate.Option) *RatchetingSchemaValidator
func (*RatchetingSchemaValidator) Validate ¶
func (r *RatchetingSchemaValidator) Validate(new interface{}, options ...ValidationOption) *validate.Result
func (*RatchetingSchemaValidator) ValidateUpdate ¶
func (r *RatchetingSchemaValidator) ValidateUpdate(new, old interface{}, options ...ValidationOption) *validate.Result
type SchemaCreateValidator ¶
type SchemaCreateValidator interface { Validate(value interface{}, options ...ValidationOption) *validate.Result }
type SchemaValidator ¶
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 ¶
func NewSchemaValidatorFromOpenAPI(openapiSchema *spec.Schema) SchemaValidator
type ValidationMetrics ¶
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 ¶
type ValidationOption func(*ValidationOptions)
func WithRatcheting ¶
func WithRatcheting(correlation *common.CorrelatedObject) ValidationOption
type ValidationOptions ¶
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. *common.CorrelatedObject }
func NewValidationOptions ¶
func NewValidationOptions(opts ...ValidationOption) ValidationOptions
Source Files ¶
formats.go metrics.go ratcheting.go validation.go
- Version
- v0.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 23 packages
- Last checked
- 1 hour ago –
Tools for package owners.