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

package objectmeta

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

Index

Functions

func Coerce

func Coerce(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot, dropInvalidFields bool) *field.Error

Coerce calls CoerceWithOptions without returning unknown field paths.

func CoerceWithOptions

func CoerceWithOptions(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot bool, opts CoerceOptions) (*field.Error, []string)

Coerce checks types of embedded ObjectMeta and TypeMeta and prunes unknown fields inside the former. It does coerce ObjectMeta and TypeMeta at the root if isResourceRoot is true. If opts.ReturnUnknownFieldPaths is true, it will return the paths of any fields that are not a part of the schema that are dropped when unmarshaling. If opts.DropInvalidFields is true, fields of wrong type will be dropped.

func GetObjectMeta

func GetObjectMeta(obj map[string]interface{}, dropMalformedFields bool) (*metav1.ObjectMeta, bool, error)

GetObjectMeta calls GetObjectMetaWithOptions without returning unknown field paths.

func GetObjectMetaWithOptions

func GetObjectMetaWithOptions(obj map[string]interface{}, opts ObjectMetaOptions) (*metav1.ObjectMeta, bool, []string, error)

GetObjectMetaWithOptions does conversion of JSON to ObjectMeta. It first tries json.Unmarshal into a metav1.ObjectMeta type. If that does not work and opts.DropMalformedFields is true, it does field-by-field best-effort conversion throwing away fields which lead to errors. If opts.ReturnedUnknownFields is true, it will UnmarshalStrict instead, returning the paths of any unknown fields it encounters (i.e. paths returned as strict errs from UnmarshalStrict)

func SetObjectMeta

func SetObjectMeta(obj map[string]interface{}, objectMeta *metav1.ObjectMeta) error

SetObjectMeta writes back ObjectMeta into a JSON data structure.

func Validate

func Validate(pth *field.Path, obj interface{}, s *structuralschema.Structural, isResourceRoot bool) field.ErrorList

Validate validates embedded ObjectMeta and TypeMeta. It also validate those at the root if isResourceRoot is true.

Types

type CoerceOptions

type CoerceOptions struct {
	// DropInvalidFields discards malformed serialized metadata fields that
	// cannot be successfully decoded to the corresponding ObjectMeta field.
	// This only applies to fields that are recognized as part of the schema,
	// but of an invalid type (i.e. cause an error when unmarshaling, rather
	// than being dropped or causing a strictErr).
	DropInvalidFields bool
	// ReturnUnknownFieldPaths will return the paths to fields that are not
	// recognized as part of the schema.
	ReturnUnknownFieldPaths bool
}

CoerceOptions gives the ability to ReturnUnknownFieldPaths for fields unrecognized by the schema or DropInvalidFields for fields that are a part of the schema, but are malformed.

type ObjectMetaOptions

type ObjectMetaOptions struct {
	// DropMalformedFields discards malformed serialized metadata fields that
	// cannot be successfully decoded to the corresponding ObjectMeta field.
	// This only applies to fields that are recognized as part of the schema,
	// but of an invalid type (i.e. cause an error when unmarshaling, rather
	// than being dropped or causing a strictErr).
	DropMalformedFields bool
	// ReturnUnknownFieldPaths will return the paths to fields that are not
	// recognized as part of the schema.
	ReturnUnknownFieldPaths bool
	// ParentPath provides the current path up to the given ObjectMeta.
	// If nil, the metadata is assumed to be at the root of the object.
	ParentPath *field.Path
}

ObjectMetaOptions provides the options for how GetObjectMeta should retrieve the object meta.

Source Files

algorithm.go coerce.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.