Documentation
¶
Overview ¶
Package checks provides shared CEL (Common Expression Language) evaluation capabilities for health check providers.
Index ¶
- func ValidateExpression(expression string, variables ...cel.EnvOption) error
- type CEL
- func (c *CEL) Compile(expr Expression) (*Check, error)
- func (c *CEL) CompileAll(exprs []Expression) ([]*Check, error)
- func (c *CEL) EvaluateAny(expr string, celCtx map[string]any) (any, error)
- func (c *CEL) EvaluateEach(expr string, celCtx map[string]any, manyKey, singleKey string) ([]any, error)
- func (c *CEL) EvaluateEachConfigured(expr string, celCtx map[string]any) ([]any, error)
- func (c *CEL) SupportsEachMode() bool
- func (c *CEL) WithIterationKeys(manyKey, singleKey string) *CEL
- type Check
- type Expression
- type IterationKeys
- type Mode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CEL ¶
type CEL struct {
// contains filtered or unexported fields
}
CEL holds configuration for CEL expression evaluation including variable declarations and a cache for compiled ASTs.
func NewCEL ¶
NewCEL creates a CEL configuration with the given variable declarations. Standard functions (like `time.Now()`) are automatically included. Each provider should create a package-level instance.
func (*CEL) Compile ¶ added in v0.7.0
func (c *CEL) Compile(expr Expression) (*Check, error)
Compile compiles a single expression into a Check.
func (*CEL) CompileAll ¶ added in v0.7.0
func (c *CEL) CompileAll(exprs []Expression) ([]*Check, error)
CompileAll compiles multiple expressions into Checks.
func (*CEL) EvaluateAny ¶ added in v0.7.0
EvaluateAny compiles and evaluates a CEL expression returning its result. Unlike Check.Evaluate(), this does not require boolean output - any type is allowed. The result is converted to native Go types for serialization. Note: Uses the cached environment but compiles the AST directly (no caching) since the boolean output validation in getOrCompileAST() doesn't apply here.
func (*CEL) EvaluateEach ¶ added in v0.7.0
func (c *CEL) EvaluateEach(expr string, celCtx map[string]any, manyKey, singleKey string) ([]any, error)
EvaluateEach evaluates a CEL expression for each item in a collection. Parameters:
- expr: the CEL expression to evaluate
- celCtx: the full CEL context
- manyKey: the key in celCtx containing a []any of items (e.g., "items")
- singleKey: the key to use when creating per-item context (e.g., "resource")
If manyKey exists and is a []any, evaluates expr against each item with context {singleKey: item}. Otherwise, evaluates expr once against the full context and returns a single-element slice.
func (*CEL) EvaluateEachConfigured ¶ added in v0.7.0
EvaluateEachConfigured evaluates a CEL expression using the configured iteration keys. If IterationKeys is configured, iterates over the collection; otherwise evaluates once. This is the preferred method for context inspection where keys come from the provider.
func (*CEL) SupportsEachMode ¶ added in v0.7.0
SupportsEachMode returns true if this CEL configuration supports per-item iteration.
func (*CEL) WithIterationKeys ¶ added in v0.7.0
WithIterationKeys configures iteration support for per-item evaluation. Providers that return collections (e.g., Kubernetes with label selectors) should call this to enable --expr-each in the context command.
type Check ¶ added in v0.7.0
type Check struct {
// contains filtered or unexported fields
}
Check represents a single compiled CEL check.
func (*Check) Evaluate ¶ added in v0.7.0
Evaluate runs this check against the context with optional runtime function bindings. Bindings are added via env.Extend() to inject runtime-specific implementations (e.g., kubernetes.Get with client context). Returns ("", nil) on success, (message, nil) on check failure, ("", err) on evaluation error.
type Expression ¶
type Expression struct {
Expression string `mapstructure:"check"`
Message string `mapstructure:"message"`
Mode string `mapstructure:"mode"` // "each" for per-item evaluation, empty for default
}
Expression represents a CEL expression validation rule
func ParseConfig ¶ added in v0.7.0
func ParseConfig(raw any) ([]Expression, error)
ParseConfig converts raw YAML config to []Expression. Accepts either:
- A slice of strings (simple expressions)
- A slice of maps with "check" and optional "message" keys
func (Expression) Each ¶ added in v0.7.0
func (e Expression) Each() bool
Each returns true if this expression should be evaluated per-item
type IterationKeys ¶ added in v0.7.0
type IterationKeys struct {
ManyKey string // Key in context containing []any of items (e.g., "items")
SingleKey string // Key used when evaluating per-item (e.g., "resource")
}
IterationKeys defines how to iterate over multiple items in a provider's context. Only applicable to providers that return collections (e.g., Kubernetes with label selectors).