apiextensions-apiserverk8s.io/apiextensions-apiserver/pkg/apiserver/schema/defaulting Index | Files

package defaulting

import "k8s.io/apiextensions-apiserver/pkg/apiserver/schema/defaulting"

Index

Functions

func Default

func Default(x interface{}, s *structuralschema.Structural)

Default does defaulting of x depending on default values in s. Default values from s are deep-copied.

PruneNonNullableNullsWithoutDefaults has left the non-nullable nulls that have a default here.

func PruneDefaults

func PruneDefaults(s *structuralschema.Structural) error

PruneDefaults prunes default values according to the schema and according to the ObjectMeta definition of the running server. It mutates the passed schema.

func PruneNonNullableNullsWithoutDefaults

func PruneNonNullableNullsWithoutDefaults(x interface{}, s *structuralschema.Structural)

PruneNonNullableNullsWithoutDefaults removes non-nullable non-defaultable null values from object.

Non-nullable nulls that have a default are left alone here and will be defaulted later.

func ValidateDefaults

func ValidateDefaults(ctx context.Context, pth *field.Path, s *structuralschema.Structural, isResourceRoot, requirePrunedDefaults bool) (field.ErrorList, error)

ValidateDefaults checks that default values validate and are properly pruned. context is passed for supporting context cancellation during cel validation

Types

type AccessorFunc

type AccessorFunc func(obj map[string]interface{}) (x interface{}, found bool, err error)

AccessorFunc returns a node x in obj on a fixed (implicitly encoded) JSON path if that path exists in obj (found==true). If it does not exist, found is false. If on the path the type of a field is wrong, an error is returned.

type SurroundingObjectFunc

type SurroundingObjectFunc func(focus interface{}) (map[string]interface{}, AccessorFunc, error)

SurroundingObjectFunc is a surrounding object builder with a given x at a leaf. Which leave is determined by the series of Index() and Child(k) calls. It also returns the inverse of the builder, namely the accessor that extracts x from the test object.

With obj, acc, _ := someSurroundingObjectFunc(x) we get:

acc(obj) == x
reflect.DeepEqual(acc(DeepCopy(obj), x) == x

where x is the original instance for slices and maps.

If after computation of acc the node holding x in obj is mutated (e.g. pruned), the accessor will return that mutated node value (e.g. the pruned x).

Example (ignoring the last two return values):

NewRootObjectFunc()(x) == x
NewRootObjectFunc().Index()(x) == [x]
NewRootObjectFunc().Index().Child("foo") == [{"foo": x}]
NewRootObjectFunc().Index().Child("foo").Child("bar") == [{"foo": {"bar":x}}]
NewRootObjectFunc().Index().Child("foo").Child("bar").Index() == [{"foo": {"bar":[x]}}]

and:

NewRootObjectFunc(), then acc(x) == x
NewRootObjectFunc().Index(), then acc([x]) == x
NewRootObjectFunc().Index().Child("foo"), then acc([{"foo": x}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar"), then acc([{"foo": {"bar":x}}]) == x
NewRootObjectFunc().Index().Child("foo").Child("bar").Index(), then acc([{"foo": {"bar":[x]}}]) == x

func NewRootObjectFunc

func NewRootObjectFunc() SurroundingObjectFunc

NewRootObjectFunc returns the identity function. The passed focus value must be an object.

func (SurroundingObjectFunc) Child

Child returns a function x => f({k: x}) and the corresponding accessor.

func (SurroundingObjectFunc) Index

Index returns a function x => f([x]) and the corresponding accessor.

func (SurroundingObjectFunc) WithTypeMeta

WithTypeMeta returns a closure with the TypeMeta fields set if they are defined. This mutates f(x).

Source Files

algorithm.go prune.go prunenulls.go surroundingobject.go validation.go

Version
v0.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
14 packages
Last checked
1 hour ago

Tools for package owners.