Documentation
¶
Overview ¶
Package constraints provides constraint parsing, extraction, and evaluation utilities for comparing recipe constraints against snapshot measurements.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstraintPath ¶
type ConstraintPath struct {
Type measurement.Type
Subtype string
Key string
}
ConstraintPath represents a parsed fully qualified constraint path. Format: {Type}.{Subtype}.{Key} Example: "K8s.server.version" -> Type="K8s", Subtype="server", Key="version"
func ParseConstraintPath ¶
func ParseConstraintPath(path string) (*ConstraintPath, error)
ParseConstraintPath parses a fully qualified constraint path. The path format is: {Type}.{Subtype}.{Key} The key portion may contain dots (e.g., "/proc/sys/kernel/osrelease").
func (*ConstraintPath) ExtractValue ¶
func (cp *ConstraintPath) ExtractValue(snap *snapshotter.Snapshot) (string, error)
ExtractValue extracts the value at this path from a snapshot. Returns the value as a string, or an error if the path doesn't exist.
func (*ConstraintPath) String ¶
func (cp *ConstraintPath) String() string
String returns the fully qualified path string.
type EvalResult ¶
type EvalResult struct {
// Passed indicates if the constraint was satisfied.
Passed bool
// Actual is the actual value extracted from the snapshot.
Actual string
// Error contains the error if evaluation failed.
Error error
}
EvalResult represents the result of evaluating a single constraint.
func Evaluate ¶
func Evaluate(constraint recipe.Constraint, snap *snapshotter.Snapshot) EvalResult
Evaluate evaluates a single constraint against a snapshot. Used by the recipe package to filter overlays based on constraint evaluation during snapshot-based recipe generation.
type Operator ¶
type Operator string
Operator represents a comparison operator in constraint expressions.
const ( // OperatorGTE represents ">=" (greater than or equal). OperatorGTE Operator = ">=" // OperatorLTE represents "<=" (less than or equal). OperatorLTE Operator = "<=" // OperatorGT represents ">" (greater than). OperatorGT Operator = ">" // OperatorLT represents "<" (less than). OperatorLT Operator = "<" // OperatorEQ represents "==" (exact match). OperatorEQ Operator = "==" // OperatorNE represents "!=" (not equal). OperatorNE Operator = "!=" // OperatorExact represents no operator (exact string match). OperatorExact Operator = "" )
type ParsedConstraint ¶
type ParsedConstraint struct {
// Operator is the comparison operator (or empty for exact match).
Operator Operator
// Value is the expected value after the operator.
Value string
// IsVersionComparison indicates if this should be treated as a version comparison.
IsVersionComparison bool
}
ParsedConstraint represents a parsed constraint expression.
func ParseConstraintExpression ¶
func ParseConstraintExpression(expr string) (*ParsedConstraint, error)
ParseConstraintExpression parses a constraint value expression. Examples:
- ">= 1.32.4" -> {Operator: ">=", Value: "1.32.4", IsVersionComparison: true}
- "ubuntu" -> {Operator: "", Value: "ubuntu", IsVersionComparison: false}
- "== 24.04" -> {Operator: "==", Value: "24.04", IsVersionComparison: false}
func (*ParsedConstraint) Evaluate ¶
func (pc *ParsedConstraint) Evaluate(actual string) (bool, error)
Evaluate evaluates the constraint against an actual value. Returns true if the constraint is satisfied, false otherwise.
func (*ParsedConstraint) String ¶
func (pc *ParsedConstraint) String() string
String returns a string representation of the parsed constraint.