common

package
v0.27.14 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaDeclType

func SchemaDeclType(s Schema, isResourceRoot bool) *apiservercel.DeclType

SchemaDeclType converts the structural schema to a CEL declaration, or returns nil if the structural schema should not be exposed in CEL expressions. Set isResourceRoot to true for the root of a custom resource or embedded resource.

Schemas with XPreserveUnknownFields not exposed unless they are objects. Array and "maps" schemas are not exposed if their items or additionalProperties schemas are not exposed. Object Properties are not exposed if their schema is not exposed.

The CEL declaration for objects with XPreserveUnknownFields does not expose unknown fields.

func UnstructuredToVal

func UnstructuredToVal(unstructured interface{}, schema Schema) ref.Val

UnstructuredToVal converts a Kubernetes unstructured data element to a CEL Val. The root schema of custom resource schema is expected contain type meta and object meta schemas. If Embedded resources do not contain type meta and object meta schemas, they will be added automatically.

func WithTypeAndObjectMeta

func WithTypeAndObjectMeta(s *spec.Schema) *spec.Schema

WithTypeAndObjectMeta ensures the kind, apiVersion and metadata.name and metadata.generateName properties are specified, making a shallow copy of the provided schema if needed.

Types

type KubeExtensions

type KubeExtensions interface {
	IsXIntOrString() bool
	IsXEmbeddedResource() bool
	IsXPreserveUnknownFields() bool
	XListType() string
	XListMapKeys() []string
}

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

func MakeMapList(sts Schema, items []interface{}) (rv MapList)

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

type SchemaOrBool interface {
	Schema() Schema
	Allows() bool
}

SchemaOrBool contains either a schema or a boolean indicating if the object can contain any fields.

type Validations

type Validations interface {
	MaxItems() *int64
	MaxLength() *int64
	MaxProperties() *int64
	Required() []string
	Enum() []any
	Nullable() bool
}

Validations contains OpenAPI validation that the CEL library uses.

Jump to

Keyboard shortcuts

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