cel

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cel implements a environment for the Common Expression Language (CEL).

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTypes = []any{
		corev1.Node{},
		corev1.NodeSpec{},
		corev1.NodeStatus{},
		corev1.Pod{},
		corev1.PodSpec{},
		corev1.ResourceRequirements{},
		corev1.PodStatus{},
		corev1.Container{},
		metav1.ObjectMeta{},
		Quantity{},
		ResourceList{},
	}
	DefaultConversions = []any{
		func(t metav1.Time) types.Timestamp {
			return types.Timestamp{Time: t.Time}
		},
		func(t *metav1.Time) types.Timestamp {
			if t == nil {
				return types.Timestamp{}
			}
			return types.Timestamp{Time: t.Time}
		},
		func(t metav1.Duration) types.Duration {
			return types.Duration{Duration: t.Duration}
		},
		func(t *metav1.Duration) types.Duration {
			if t == nil {
				return types.Duration{}
			}
			return types.Duration{Duration: t.Duration}
		},
		func(t resource.Quantity) Quantity {
			return NewQuantity(&t)
		},
		NewResourceList,
	}
	DefaultFuncs = map[string][]any{
					// contains filtered or unexported fields
	}
)
View Source
var (
	// QuantityType singleton.
	QuantityType = cel.ObjectType("kubernetes.Quantity",
		traits.AdderType,
		traits.ComparerType,
		traits.DividerType,
		traits.MultiplierType,
		traits.NegatorType,
		traits.SubtractorType,
	)
)
View Source
var (
	// ResourceListType singleton.
	ResourceListType = cel.ObjectType("kubernetes.ResourceList",
		traits.ContainerType,
		traits.IndexerType,
		traits.SizerType,
	)
)

Functions

func AsFloat64

func AsFloat64(refVal ref.Val) (float64, error)

AsFloat64 returns the float64 value of a ref.Val

func AsString

func AsString(refVal ref.Val) (string, error)

AsString returns the string value of a ref.Val

func FuncsToMethods

func FuncsToMethods(funcs map[string][]any) map[string][]any

FuncsToMethods converts a map of function names to functions to a map of method names to methods.

Types

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment is environment in which cel programs are executed

func NewEnvironment

func NewEnvironment(conf EnvironmentConfig) (*Environment, error)

NewEnvironment returns a Environment with the given configuration

func (*Environment) Compile

func (e *Environment) Compile(src string) (cel.Program, error)

Compile is responsible for compiling a cel program

type EnvironmentConfig

type EnvironmentConfig struct {
	Conversions []any
	Types       []any
	Vars        map[string]any
	Funcs       map[string][]any
	Methods     map[string][]any
}

EnvironmentConfig holds configuration for a cel program

type Program

type Program = cel.Program

Program is a cel program

type Quantity

type Quantity struct {
	Quantity *resource.Quantity
}

Quantity is a wrapper around k8s.io/apimachinery/pkg/api/resource.Quantity

func NewQuantity

func NewQuantity(q *resource.Quantity) Quantity

NewQuantity creates a new Quantity

func NewQuantityFromString

func NewQuantityFromString(s string) (Quantity, error)

NewQuantityFromString creates a new Quantity from a string

func (Quantity) Add

func (q Quantity) Add(other ref.Val) ref.Val

Add implements the traits.Adder interface.

func (Quantity) Compare

func (q Quantity) Compare(other ref.Val) ref.Val

Compare implements the traits.Comparer interface.

func (Quantity) ConvertToNative

func (q Quantity) ConvertToNative(typeDesc reflect.Type) (any, error)

ConvertToNative implements the ref.Val interface.

func (Quantity) ConvertToType

func (q Quantity) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements the ref.Val interface.

func (Quantity) Divide

func (q Quantity) Divide(other ref.Val) ref.Val

Divide implements the traits.Divider interface.

func (Quantity) Equal

func (q Quantity) Equal(other ref.Val) ref.Val

Equal implements the ref.Val interface.

func (Quantity) IsZeroValue

func (q Quantity) IsZeroValue() bool

IsZeroValue implements the traits.Zeroer interface.

func (Quantity) Multiply

func (q Quantity) Multiply(other ref.Val) ref.Val

Multiply implements the traits.Multiplier interface.

func (Quantity) Negate

func (q Quantity) Negate() ref.Val

Negate implements the traits.Negater interface.

func (Quantity) Subtract

func (q Quantity) Subtract(subtrahend ref.Val) ref.Val

Subtract implements the traits.Subtractor interface.

func (Quantity) Type

func (q Quantity) Type() ref.Type

Type implements the ref.Val interface.

func (Quantity) Value

func (q Quantity) Value() any

Value implements the ref.Val interface.

type ResourceList

type ResourceList struct {
	List corev1.ResourceList
}

ResourceList is a wrapper around k8s.io/api/core/v1.ResourceList

func NewResourceList

func NewResourceList(list corev1.ResourceList) ResourceList

NewResourceList creates a new ResourceList

func (ResourceList) Contains

func (r ResourceList) Contains(index ref.Val) ref.Val

Contains implements the traits.Container interface.

func (ResourceList) ConvertToNative

func (r ResourceList) ConvertToNative(typeDesc reflect.Type) (any, error)

ConvertToNative implements the ref.Val interface.

func (ResourceList) ConvertToType

func (r ResourceList) ConvertToType(typeValue ref.Type) ref.Val

ConvertToType implements the ref.Val interface.

func (ResourceList) Equal

func (r ResourceList) Equal(other ref.Val) ref.Val

Equal implements the ref.Val interface.

func (ResourceList) Get

func (r ResourceList) Get(index ref.Val) ref.Val

Get implements the traits.Indexer interface.

func (ResourceList) IsZeroValue

func (r ResourceList) IsZeroValue() bool

IsZeroValue implements the traits.Zeroer interface.

func (ResourceList) Size

func (r ResourceList) Size() ref.Val

Size implements the traits.Sizer interface.

func (ResourceList) Type

func (r ResourceList) Type() ref.Type

Type implements the ref.Val interface.

func (ResourceList) Value

func (r ResourceList) Value() any

Value implements the ref.Val interface.

type Val

type Val = ref.Val

Val is a cel value

Jump to

Keyboard shortcuts

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