dynamic-resource-allocationk8s.io/dynamic-resource-allocation/cel Index | Files

package cel

import "k8s.io/dynamic-resource-allocation/cel"

Index

Functions

func DRAConsumableCapacity

func DRAConsumableCapacity() bool

func GetCompiler

func GetCompiler(features Features) *compiler

func SetDRAConsumableCapacity

func SetDRAConsumableCapacity()

func UnsetDRAConsumableCapacity

func UnsetDRAConsumableCapacity()

Types

type Cache

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

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

func NewCache

func NewCache(maxCacheEntries int, features Features) *Cache

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

The features are used to get a suitable compiler.

func (*Cache) Check

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

func (*Cache) GetOrCompile

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.

Cost estimation is disabled.

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
	AllowMultipleAllocations *bool
	Attributes               map[resourceapi.QualifiedName]resourceapi.DeviceAttribute
	Capacity                 map[resourceapi.QualifiedName]resourceapi.DeviceCapacity
}

Device defines the input values for a CEL selector expression.

type Features

type Features struct {
	EnableConsumableCapacity bool
}

Features contains feature gates supported by the package.

type Options

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

	// DisableCostEstimation can be set to skip estimating the worst-case CEL cost.
	// If disabled or after an error, [CompilationResult.MaxCost] will be set to [math.Uint64].
	DisableCostEstimation bool
}

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

Source Files

cache.go compile.go feature_enabled.go

Version
v0.34.0-rc.0
Published
Aug 8, 2025
Platform
darwin/amd64
Imports
24 packages
Last checked
3 minutes ago

Tools for package owners.