Documentation
¶
Overview ¶
Package cel implements a environment for the Common Expression Language (CEL).
Index ¶
- Variables
- func AsFloat64(refVal ref.Val) (float64, error)
- func AsString(refVal ref.Val) (string, error)
- func FuncsToMethods(funcs map[string][]any) map[string][]any
- type Environment
- type EnvironmentConfig
- type Program
- type Quantity
- func (q Quantity) Add(other ref.Val) ref.Val
- func (q Quantity) Compare(other ref.Val) ref.Val
- func (q Quantity) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (q Quantity) ConvertToType(typeVal ref.Type) ref.Val
- func (q Quantity) Divide(other ref.Val) ref.Val
- func (q Quantity) Equal(other ref.Val) ref.Val
- func (q Quantity) IsZeroValue() bool
- func (q Quantity) Multiply(other ref.Val) ref.Val
- func (q Quantity) Negate() ref.Val
- func (q Quantity) Subtract(subtrahend ref.Val) ref.Val
- func (q Quantity) Type() ref.Type
- func (q Quantity) Value() any
- type ResourceList
- func (r ResourceList) Contains(index ref.Val) ref.Val
- func (r ResourceList) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (r ResourceList) ConvertToType(typeValue ref.Type) ref.Val
- func (r ResourceList) Equal(other ref.Val) ref.Val
- func (r ResourceList) Get(index ref.Val) ref.Val
- func (r ResourceList) IsZeroValue() bool
- func (r ResourceList) Size() ref.Val
- func (r ResourceList) Type() ref.Type
- func (r ResourceList) Value() any
- type Val
Constants ¶
This section is empty.
Variables ¶
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 } )
var ( // QuantityType singleton. QuantityType = cel.ObjectType("kubernetes.Quantity", traits.AdderType, traits.ComparerType, traits.DividerType, traits.MultiplierType, traits.NegatorType, traits.SubtractorType, ) )
var ( // ResourceListType singleton. ResourceListType = cel.ObjectType("kubernetes.ResourceList", traits.ContainerType, traits.IndexerType, traits.SizerType, ) )
Functions ¶
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
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 Quantity ¶
Quantity is a wrapper around k8s.io/apimachinery/pkg/api/resource.Quantity
func NewQuantity ¶
NewQuantity creates a new Quantity
func NewQuantityFromString ¶
NewQuantityFromString creates a new Quantity from a string
func (Quantity) ConvertToNative ¶
ConvertToNative implements the ref.Val interface.
func (Quantity) ConvertToType ¶
ConvertToType implements the ref.Val interface.
func (Quantity) IsZeroValue ¶
IsZeroValue implements the traits.Zeroer 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.