cel

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

cel provides utilities for evaluating Common Expression Language (CEL) expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStatusReader

func NewStatusReader(ctx context.Context, mapper meta.RESTMapper, gk schema.GroupKind,
	se *StatusEvaluator) engine.StatusReader

NewStatusReader returns a new StatusReader for the given GroupKind and healthcheck expressions. The context is used to control the execution of the underlying operations performed by the the reader.

func PollerWithCustomHealthChecks

func PollerWithCustomHealthChecks(ctx context.Context,
	healthchecks []kustomize.CustomHealthCheck) ([]func(meta.RESTMapper) engine.StatusReader, error)

PollerWithCustomHealthChecks creates a list of constructors for custom status readers from a list of custom health checks. If there are multiple healthchecks defined for the same GroupKind, only the first one is used. The context is used to control the execution of the underlying status readers.

Types

type Expression

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

Expression represents a parsed CEL expression.

func NewExpression

func NewExpression(expr string, opts ...Option) (*Expression, error)

NewExpression parses the given CEL expression and returns a new Expression.

func (*Expression) EvaluateBoolean

func (e *Expression) EvaluateBoolean(ctx context.Context, data map[string]any) (bool, error)

EvaluateBoolean evaluates the expression with the given data and returns the result as a boolean.

func (*Expression) EvaluateString added in v0.55.0

func (e *Expression) EvaluateString(ctx context.Context, data map[string]any) (string, error)

EvaluateString evaluates the expression with the given data and returns the result as a string.

type Option

type Option func(*options)

Option is a function that configures the CEL expression.

func WithCompile

func WithCompile() Option

WithCompile specifies that the expression should be compiled, which provides stricter checks at parse time, before evaluation.

func WithOutputType

func WithOutputType(t *cel.Type) Option

WithOutputType specifies the expected output type of the expression.

func WithStructVariables

func WithStructVariables(vars ...string) Option

WithStructVariables declares variables of type google.protobuf.Struct.

type StatusEvaluator

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

StatusEvaluator evaluates the health status of a custom resource object.

func NewStatusEvaluator

func NewStatusEvaluator(exprs *kustomize.HealthCheckExpressions) (*StatusEvaluator, error)

NewStatusEvaluator returns a new StatusEvaluator.

func (*StatusEvaluator) Evaluate

Evaluate evaluates the health status of a custom resource object according to the rules defined in RFC 0009:

First we check if the object has the field status.observedGeneration. If it does, and the value is different from metadata.generation, we return the status InProgress.

Then we evaluate the healthcheck expressions in the following order: - InProgress: if true, return status InProgress - Failed: if true, return status Failed - Current: if true, return status Current

If none of the expressions are true, we return status InProgress.

type StatusReader

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

StatusReader implements the engine.StatusReader interface for a specific GroupKind and set of healthcheck expressions.

func (*StatusReader) ReadStatus

func (g *StatusReader) ReadStatus(ctx context.Context, reader engine.ClusterReader,
	resource object.ObjMetadata) (*event.ResourceStatus, error)

ReadStatus reads the status of the resource with the given metadata.

func (*StatusReader) ReadStatusForObject

func (g *StatusReader) ReadStatusForObject(ctx context.Context, reader engine.ClusterReader,
	resource *unstructured.Unstructured) (*event.ResourceStatus, error)

ReadStatusForObject reads the status of the given resource.

func (*StatusReader) Supports

func (g *StatusReader) Supports(gk schema.GroupKind) bool

Supports returns true if the StatusReader supports the given GroupKind.