Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CorrelatedObject ¶
type CorrelatedObject struct {
OldValue interface{}
Value interface{}
// to determine how to correlate the old object.
Schema Schema
// children.
Duration *time.Duration
// contains filtered or unexported fields
}
CorrelatedObject represents a node in a tree of objects that are being validated. It is used to keep track of the old value of an object during traversal of the new value. It is also used to cache the results of DeepEqual comparisons between the old and new values of objects.
All receiver functions support being called on `nil` to support ergonomic recursive descent. The nil `CorrelatedObject` represents an uncorrelatable node in the tree.
CorrelatedObject is not thread-safe. It is the responsibility of the caller to handle concurrency, if any.
func NewCorrelatedObject ¶
func NewCorrelatedObject(new, old interface{}, schema Schema) *CorrelatedObject
func (*CorrelatedObject) CachedDeepEqual ¶
func (r *CorrelatedObject) CachedDeepEqual() (res bool)
CachedDeepEqual is equivalent to reflect.DeepEqual, but caches the results in the tree of ratchetInvocationScratch objects on the way:
For objects and arrays, this function will make a best effort to make use of past DeepEqual checks performed by this Node's children, if available.
If a lazy computation could not be found for all children possibly due to validation logic short circuiting and skipping the children, then this function simply defers to reflect.DeepEqual.
func (*CorrelatedObject) Index ¶
func (r *CorrelatedObject) Index(i int) *CorrelatedObject
Index returns the child of the receiver at the given index. Returns nil if the given index is out of bounds, or its value is not correlatable to an old value. If receiver is nil or if the new value is not an array, returns nil.
func (*CorrelatedObject) Key ¶
func (r *CorrelatedObject) Key(field string) *CorrelatedObject
Key returns the child of the receiver with the given name. Returns nil if the given name is does not exist in the new object, or its value is not correlatable to an old value. If receiver is nil or if the new value is not an object/map, returns nil.
type KubeExtensions ¶
type KubeExtensions interface {
IsXIntOrString() bool
IsXEmbeddedResource() bool
IsXPreserveUnknownFields() bool
XListType() string
XListMapKeys() []string
XMapType() string
XValidations() []ValidationRule
}
KubeExtensions contains Kubernetes-specific extensions to the OpenAPI schema.
type MapList ¶
type MapList interface {
// Get returns the first element having given key, for all
// x-kubernetes-list-map-keys, to the provided object. If the provided object isn't itself a valid MapList element,
// get returns nil.
Get(interface{}) interface{}
}
MapList provides a "lookup by key" operation for lists (arrays) with x-kubernetes-list-type=map.
func MakeMapList ¶
MakeMapList returns a queryable interface over the provided x-kubernetes-list-type=map keyedItems. If the provided schema is _not_ an array with x-kubernetes-list-type=map, returns an empty mapList.
type Schema ¶
type Schema interface {
// Type returns the OpenAPI type.
// Multiple types are not supported. It should return
// empty string if no type is specified.
Type() string
// Format returns the OpenAPI format. May be empty
Format() string
// Items returns the OpenAPI items. or nil of this field does not exist or
// contains no schema.
Items() Schema
// Properties returns the OpenAPI properties, or nil if this field does not
// exist.
// The values of the returned map are of the adapted type.
Properties() map[string]Schema
// AdditionalProperties returns the OpenAPI additional properties field,
// or nil if this field does not exist.
AdditionalProperties() SchemaOrBool
// Default returns the OpenAPI default field, or nil if this field does not exist.
Default() any
Validations
KubeExtensions
// WithTypeAndObjectMeta returns a schema that has the type and object meta set.
// the type includes "kind", "apiVersion" field
// the "metadata" field requires "name" and "generateName" to be set
// The original schema must not be mutated. Make a copy if necessary.
WithTypeAndObjectMeta() Schema
}
Schema is the adapted type for an OpenAPI schema that CEL uses. This schema does not cover all OpenAPI fields but only these CEL requires are exposed as getters.
type SchemaOrBool ¶
SchemaOrBool contains either a schema or a boolean indicating if the object can contain any fields.
type ValidationRule ¶
type ValidationRule interface {
Rule() string
Message() string
MessageExpression() string
FieldPath() string
}
ValidationRule represents a single x-kubernetes-validations rule.
type Validations ¶
type Validations interface {
Pattern() string
Minimum() *float64
IsExclusiveMinimum() bool
Maximum() *float64
IsExclusiveMaximum() bool
MultipleOf() *float64
MinItems() *int64
MaxItems() *int64
MinLength() *int64
MaxLength() *int64
MinProperties() *int64
MaxProperties() *int64
Required() []string
Enum() []any
Nullable() bool
UniqueItems() bool
AllOf() []Schema
OneOf() []Schema
AnyOf() []Schema
Not() Schema
}
Validations contains OpenAPI validation that the CEL library uses.