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

package cel

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

Index

Constants

const ScopedVarName = "self"

ScopedVarName is the variable name assigned to the locally scoped data element of a CEL valid.

Functions

func NewValidationActivation

func NewValidationActivation(obj interface{}, structural *schema.Structural) *validationActivation

func UnstructuredToVal

func UnstructuredToVal(unstructured interface{}, schema *structuralschema.Structural) 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.

Types

type CompilationResult

type CompilationResult struct {
	Program cel.Program
	Error   *Error
}

CompilationResult represents the cel compilation result for one rule

func Compile

func Compile(s *schema.Structural, isResourceRoot bool) ([]CompilationResult, error)

Compile compiles all the XValidations rules (without recursing into the schema) and returns a slice containing a CompilationResult for each ValidationRule, or an error. Each CompilationResult may contain: / - non-nil Program, nil Error: The program was compiled successfully

type Error

type Error struct {
	Type   ErrorType
	Detail string
}

Error is an implementation of the 'error' interface, which represents a XValidation error.

func (*Error) Error

func (v *Error) Error() string

Error implements the error interface.

type ErrorType

type ErrorType string

ErrorType is a machine readable value providing more detail about why a XValidation is invalid.

const (
	// ErrorTypeRequired is used to report withNullable values that are not
	// provided (e.g. empty strings, null values, or empty arrays).  See
	// Required().
	ErrorTypeRequired ErrorType = "RuleRequired"
	// ErrorTypeInvalid is used to report malformed values
	ErrorTypeInvalid ErrorType = "RuleInvalid"
	// ErrorTypeInternal is used to report other errors that are not related
	// to user input.  See InternalError().
	ErrorTypeInternal ErrorType = "InternalError"
)

type Validator

type Validator struct {
	Items      *Validator
	Properties map[string]Validator

	AdditionalProperties *Validator
	// contains filtered or unexported fields
}

Validator parallels the structure of schema.Structural and includes the compiled CEL programs for the x-kubernetes-validations of each schema node.

func NewValidator

func NewValidator(s *schema.Structural) *Validator

NewValidator returns compiles all the CEL programs defined in x-kubernetes-validations extensions of the Structural schema and returns a custom resource validator that contains nested validators for all items, properties and additionalProperties that transitively contain validator rules. Returns nil only if there no validator rules in the Structural schema. May return a validator containing only errors.

func (*Validator) Validate

func (s *Validator) Validate(fldPath *field.Path, sts *schema.Structural, obj interface{}) field.ErrorList

Validate validates all x-kubernetes-validations rules in Validator against obj and returns any errors.

Source Files

compilation.go errors.go validation.go values.go

Version
v0.23.13
Published
Oct 13, 2022
Platform
js/wasm
Imports
20 packages
Last checked
9 minutes ago

Tools for package owners.