cel

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 21 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCompiler

func GetCompiler() *compiler

Types

type Cache added in v0.32.0

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

Cache is a thread-safe LRU cache for a compiled CEL expression.

func NewCache added in v0.32.0

func NewCache(maxCacheEntries int) *Cache

NewCache creates a cache. The maximum number of entries determines how many entries are cached at most before dropping the oldest entry.

func (*Cache) GetOrCompile added in v0.32.0

func (c *Cache) GetOrCompile(expression string) CompilationResult

GetOrCompile checks whether the cache already has a compilation result and returns that if available. Otherwise it compiles, stores successful results and returns the new result.

type CompilationResult

type CompilationResult struct {
	Program     cel.Program
	Error       *apiservercel.Error
	Expression  string
	OutputType  *cel.Type
	Environment *cel.Env

	// MaxCost represents the worst-case cost of the compiled MessageExpression in terms of CEL's cost units,
	// as used by cel.EstimateCost.
	MaxCost uint64
	// contains filtered or unexported fields
}

CompilationResult represents a compiled expression.

func (CompilationResult) DeviceMatches

func (c CompilationResult) DeviceMatches(ctx context.Context, input Device) (bool, *cel.EvalDetails, error)

type Device

type Device struct {
	// Driver gets used as domain for any attribute which does not already
	// have a domain prefix. If set, then it is also made available as a
	// string attribute.
	Driver     string
	Attributes map[resourceapi.QualifiedName]resourceapi.DeviceAttribute
	Capacity   map[resourceapi.QualifiedName]resourceapi.DeviceCapacity
}

Device defines the input values for a CEL selector expression.

type Options added in v0.32.0

type Options struct {
	// EnvType allows to override the default environment type [environment.StoredExpressions].
	EnvType *environment.Type

	// CostLimit allows overriding the default runtime cost limit [resourceapi.CELSelectorExpressionMaxCost].
	CostLimit *uint64
}

Options contains several additional parameters for [CompileCELExpression]. All of them have reasonable defaults.

Jump to

Keyboard shortcuts

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