Documentation
¶
Overview ¶
Package validator provides recipe constraint validation against system snapshots.
Overview ¶
The validator package evaluates recipe constraints against actual system measurements captured in snapshots. It supports version comparison operators and exact string matching to determine if a cluster meets the requirements specified in a recipe.
Constraint Format ¶
Constraints use fully qualified measurement paths in the format: {Type}.{Subtype}.{Key}
Examples:
K8s.server.version -> Kubernetes server version OS.release.ID -> Operating system identifier (e.g., "ubuntu") OS.release.VERSION_ID -> OS version (e.g., "24.04") OS.sysctl./proc/sys/kernel/osrelease -> Kernel version
Supported Operators ¶
The following comparison operators are supported in constraint values:
- ">=" - Greater than or equal (version comparison)
- "<=" - Less than or equal (version comparison)
- ">" - Greater than (version comparison)
- "<" - Less than (version comparison)
- "==" - Exact match (string or version)
- "!=" - Not equal (string or version)
- (no operator) - Exact string match
Usage ¶
Basic validation:
v := validator.New()
result, err := v.Validate(ctx, recipe, snapshot)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Status: %s\n", result.Summary.Status)
for _, r := range result.Results {
fmt.Printf(" %s: expected %q, got %q - %v\n",
r.Name, r.Expected, r.Actual, r.Status)
}
Result Structure ¶
ValidationResult contains:
- Summary: Overall pass/fail counts and status
- Results: Per-constraint validation results with expected/actual values
Error Handling ¶
Constraints that cannot be evaluated (e.g., path not found in snapshot) are marked as "skipped" with appropriate warning messages, allowing partial validation results to be returned.
Index ¶
- Constants
- Variables
- type CheckResult
- type ComponentActual
- type ComponentExpected
- type ComponentResult
- type ConstraintEvalResult
- type ConstraintPath
- type ConstraintStatus
- type ConstraintValidation
- type Operator
- type Option
- func WithCleanup(cleanup bool) Option
- func WithImage(image string) Option
- func WithImagePullSecrets(secrets []string) Option
- func WithNamespace(namespace string) Option
- func WithNoCluster(noCluster bool) Option
- func WithRunID(runID string) Option
- func WithTolerations(tolerations []corev1.Toleration) Option
- func WithVersion(version string) Option
- type ParsedConstraint
- type PhaseResult
- type ValidationPhaseName
- type ValidationResult
- type ValidationStatus
- type ValidationSummary
- type Validator
- func (v *Validator) Validate(ctx context.Context, recipeResult *recipe.RecipeResult, ...) (*ValidationResult, error)
- func (v *Validator) ValidatePhase(ctx context.Context, phase ValidationPhaseName, ...) (*ValidationResult, error)
- func (v *Validator) ValidatePhases(ctx context.Context, phases []ValidationPhaseName, ...) (*ValidationResult, error)
Constants ¶
const ( DefaultReadinessTimeout = defaults.ValidateReadinessTimeout DefaultDeploymentTimeout = defaults.ValidateDeploymentTimeout DefaultPerformanceTimeout = defaults.ValidatePerformanceTimeout DefaultConformanceTimeout = defaults.ValidateConformanceTimeout )
Phase timeout aliases — defined in pkg/defaults/timeouts.go.
const (
// APIVersion is the API version for validation results.
APIVersion = "aicr.nvidia.com/v1alpha1"
)
Variables ¶
var PhaseOrder = []ValidationPhaseName{ PhaseReadiness, PhaseDeployment, PhasePerformance, PhaseConformance, }
PhaseOrder defines the canonical execution order for validation phases. Readiness and deployment must run before performance or conformance.
Functions ¶
This section is empty.
Types ¶
type CheckResult ¶
type CheckResult struct {
// Name is the check identifier.
Name string `json:"name" yaml:"name"`
// Status is the check outcome.
Status ValidationStatus `json:"status" yaml:"status"`
// Reason explains why the check failed or was skipped.
Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`
// Remediation provides actionable guidance for fixing failures.
Remediation string `json:"remediation,omitempty" yaml:"remediation,omitempty"`
// Duration is how long this check took to run.
Duration time.Duration `json:"duration,omitempty" yaml:"duration,omitempty"`
// Artifacts contains diagnostic evidence captured during live check execution.
// Ephemeral: only populated during live validation runs, never persisted.
Artifacts []checks.Artifact `json:"-" yaml:"-"`
}
CheckResult represents the result of a named validation check.
type ComponentActual ¶ added in v0.7.10
type ComponentActual struct {
// Chart is the Helm chart reference found in the snapshot.
Chart string `json:"chart,omitempty" yaml:"chart,omitempty"`
// Version is the chart or app version found in the snapshot.
Version string `json:"version,omitempty" yaml:"version,omitempty"`
// Namespace is the namespace where the component was found.
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// Source is the repository URL found in the snapshot (for ArgoCD/Kustomize).
Source string `json:"source,omitempty" yaml:"source,omitempty"`
}
ComponentActual captures the deployed configuration found in the snapshot.
type ComponentExpected ¶ added in v0.7.10
type ComponentExpected struct {
// Chart is the Helm chart reference (e.g., "nvidia/gpu-operator").
Chart string `json:"chart,omitempty" yaml:"chart,omitempty"`
// Version is the expected chart or app version.
Version string `json:"version,omitempty" yaml:"version,omitempty"`
// Namespace is the target deployment namespace.
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// Source is the Kustomize source URI.
Source string `json:"source,omitempty" yaml:"source,omitempty"`
}
ComponentExpected captures the recipe's intended deployment configuration.
type ComponentResult ¶ added in v0.7.10
type ComponentResult struct {
// Name is the component identifier (e.g., "gpu-operator").
Name string `json:"name" yaml:"name"`
// Type is the component type (e.g., "helm", "kustomize").
Type string `json:"type" yaml:"type"`
// Status is the outcome.
Status ValidationStatus `json:"status" yaml:"status"`
// Expected captures the recipe's intended deployment configuration.
Expected ComponentExpected `json:"expected" yaml:"expected"`
// Actual captures the deployed configuration found in the snapshot.
Actual ComponentActual `json:"actual,omitempty" yaml:"actual,omitempty"`
// Message provides additional context, especially for mismatches or skipped components.
Message string `json:"message,omitempty" yaml:"message,omitempty"`
}
ComponentResult is retained for backward-compatible deserialization of older results.
type ConstraintEvalResult ¶
type ConstraintEvalResult 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 (e.g., value not found).
Error error
}
ConstraintEvalResult represents the result of evaluating a single constraint.
func EvaluateConstraint ¶
func EvaluateConstraint(constraint recipe.Constraint, snap *snapshotter.Snapshot) ConstraintEvalResult
EvaluateConstraint evaluates a single constraint against a snapshot. This is a standalone function that can be used by other packages without creating a full Validator instance. Used by the recipe package to filter overlays based on constraint evaluation during snapshot-based recipe generation.
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 ConstraintStatus ¶
type ConstraintStatus string
ConstraintStatus represents the outcome of evaluating a single constraint.
const ( // ConstraintStatusPassed indicates the constraint was satisfied. ConstraintStatusPassed ConstraintStatus = "passed" // ConstraintStatusFailed indicates the constraint was not satisfied. ConstraintStatusFailed ConstraintStatus = "failed" // ConstraintStatusSkipped indicates the constraint couldn't be evaluated. ConstraintStatusSkipped ConstraintStatus = "skipped" )
type ConstraintValidation ¶
type ConstraintValidation struct {
// Name is the fully qualified constraint name (e.g., "K8s.server.version").
Name string `json:"name" yaml:"name"`
// Expected is the constraint expression from the recipe (e.g., ">= 1.32.4").
Expected string `json:"expected" yaml:"expected"`
// Actual is the value found in the snapshot (e.g., "v1.33.5-eks-3025e55").
Actual string `json:"actual" yaml:"actual"`
// Status is the outcome of this constraint evaluation.
Status ConstraintStatus `json:"status" yaml:"status"`
// Message provides additional context, especially for failures or skipped constraints.
Message string `json:"message,omitempty" yaml:"message,omitempty"`
}
ConstraintValidation represents the result of evaluating a single constraint.
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 Option ¶
type Option func(*Validator)
Option is a functional option for configuring Validator instances.
func WithCleanup ¶
WithCleanup returns an Option that controls cleanup of validation resources. When false, Jobs, ConfigMaps, and RBAC resources are kept for debugging.
func WithImagePullSecrets ¶
WithImagePullSecrets returns an Option that sets image pull secrets for validation Jobs.
func WithNamespace ¶
WithNamespace returns an Option that sets the namespace for validation jobs.
func WithNoCluster ¶
WithNoCluster returns an Option that controls cluster access. When set to true, validation runs in dry-run mode without connecting to cluster.
func WithRunID ¶
WithRunID returns an Option that sets the RunID for this validation run. Used when resuming a previous validation run.
func WithTolerations ¶ added in v0.8.2
func WithTolerations(tolerations []corev1.Toleration) Option
WithTolerations returns an Option that sets tolerations for validation phase Jobs.
func WithVersion ¶
WithVersion returns an Option that sets the Validator version string.
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.
type PhaseResult ¶
type PhaseResult struct {
// Status is the overall status of this phase.
Status ValidationStatus `json:"status" yaml:"status"`
// Constraints contains per-constraint results for this phase.
Constraints []ConstraintValidation `json:"constraints,omitempty" yaml:"constraints,omitempty"`
// Checks contains results of named validation checks.
Checks []CheckResult `json:"checks,omitempty" yaml:"checks,omitempty"`
// Components is retained for backward-compatible deserialization of older results.
// No longer populated; per-component health is validated via Chainsaw health checks.
Components []ComponentResult `json:"components,omitempty" yaml:"components,omitempty"`
// Reason explains why the phase was skipped or failed.
Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`
// Duration is how long this phase took to run.
Duration time.Duration `json:"duration,omitempty" yaml:"duration,omitempty"`
}
PhaseResult represents the result of a single validation phase.
type ValidationPhaseName ¶
type ValidationPhaseName string
ValidationPhaseName represents the name of a validation phase.
const ( // PhaseReadiness is the readiness validation phase. PhaseReadiness ValidationPhaseName = "readiness" // PhaseDeployment is the deployment validation phase. PhaseDeployment ValidationPhaseName = "deployment" // PhasePerformance is the performance validation phase. PhasePerformance ValidationPhaseName = "performance" // PhaseConformance is the conformance validation phase. PhaseConformance ValidationPhaseName = "conformance" // PhaseAll runs all phases sequentially. PhaseAll ValidationPhaseName = "all" )
type ValidationResult ¶
type ValidationResult struct {
header.Header `json:",inline" yaml:",inline"`
// RunID is a unique identifier for this validation run.
// Used for resume functionality and correlating resources.
// Format: YYYYMMDD-HHMMSS-RANDOM (e.g., "20260206-140523-a3f9")
RunID string `json:"runID,omitempty" yaml:"runID,omitempty"`
// RecipeSource is the path/URI of the recipe that was validated.
RecipeSource string `json:"recipeSource" yaml:"recipeSource"`
// SnapshotSource is the path/URI of the snapshot used for validation.
SnapshotSource string `json:"snapshotSource" yaml:"snapshotSource"`
// Summary contains aggregate validation statistics.
Summary ValidationSummary `json:"summary" yaml:"summary"`
// Results contains per-constraint validation details (legacy, for backward compatibility).
Results []ConstraintValidation `json:"results,omitempty" yaml:"results,omitempty"`
// Phases contains per-phase validation results (multi-phase validation).
Phases map[string]*PhaseResult `json:"phases,omitempty" yaml:"phases,omitempty"`
}
ValidationResult represents the complete validation outcome.
func NewValidationResult ¶
func NewValidationResult() *ValidationResult
NewValidationResult creates a new ValidationResult with initialized slices.
type ValidationStatus ¶
type ValidationStatus string
ValidationStatus represents the overall validation outcome.
const ( // ValidationStatusPass indicates all constraints passed. ValidationStatusPass ValidationStatus = "pass" // ValidationStatusFail indicates one or more constraints failed. ValidationStatusFail ValidationStatus = "fail" // ValidationStatusPartial indicates some constraints couldn't be evaluated. ValidationStatusPartial ValidationStatus = "partial" // ValidationStatusSkipped indicates a phase was skipped (due to dependency failure). ValidationStatusSkipped ValidationStatus = "skipped" // ValidationStatusWarning indicates warnings but no hard failures. ValidationStatusWarning ValidationStatus = "warning" )
type ValidationSummary ¶
type ValidationSummary struct {
// Passed is the count of constraints that were satisfied.
Passed int `json:"passed" yaml:"passed"`
// Failed is the count of constraints that were not satisfied.
Failed int `json:"failed" yaml:"failed"`
// Skipped is the count of constraints that couldn't be evaluated.
Skipped int `json:"skipped" yaml:"skipped"`
// Total is the total number of constraints evaluated.
Total int `json:"total" yaml:"total"`
// Status is the overall validation status.
Status ValidationStatus `json:"status" yaml:"status"`
// Duration is how long the validation took.
Duration time.Duration `json:"duration" yaml:"duration"`
}
ValidationSummary contains aggregate statistics about the validation.
type Validator ¶
type Validator struct {
// Version is the validator version (typically the CLI version).
Version string
// Namespace is the Kubernetes namespace where validation jobs will run.
// Defaults to "aicr-validation" if not specified.
Namespace string
// Image is the container image to use for validation Jobs.
// Must include Go toolchain for running tests.
// Defaults to "ghcr.io/nvidia/aicr-validator:latest".
Image string
// RunID is a unique identifier for this validation run.
// Used to scope all resources (ConfigMaps, Jobs) and enable resumability.
// Format: YYYYMMDD-HHMMSS-RANDOM (e.g., "20260206-140523-a3f9")
RunID string
// Cleanup controls whether to delete Jobs, ConfigMaps, and RBAC resources after validation.
// Defaults to true. Set to false to keep resources for debugging.
Cleanup bool
// ImagePullSecrets are secret names for pulling images from private registries.
ImagePullSecrets []string
// NoCluster controls whether to skip actual cluster operations (dry-run mode).
// When true, validation runs without connecting to Kubernetes cluster.
NoCluster bool
// Tolerations are applied to validation phase Jobs for scheduling on tainted nodes.
// Defaults to tolerate-all so Jobs can schedule on any node regardless of taints.
Tolerations []corev1.Toleration
}
Validator evaluates recipe constraints against snapshot measurements.
func (*Validator) Validate ¶
func (v *Validator) Validate(ctx context.Context, recipeResult *recipe.RecipeResult, snap *snapshotter.Snapshot) (*ValidationResult, error)
Validate evaluates all constraints from the recipe against the snapshot. Returns a ValidationResult containing per-constraint results and summary.
func (*Validator) ValidatePhase ¶
func (v *Validator) ValidatePhase( ctx context.Context, phase ValidationPhaseName, recipeResult *recipe.RecipeResult, snap *snapshotter.Snapshot, ) (*ValidationResult, error)
ValidatePhase runs validation for a specific phase. This is the main entry point for phase-based validation.
func (*Validator) ValidatePhases ¶
func (v *Validator) ValidatePhases( ctx context.Context, phases []ValidationPhaseName, recipeResult *recipe.RecipeResult, snap *snapshotter.Snapshot, ) (*ValidationResult, error)
ValidatePhases runs validation for multiple specified phases. If no phases are specified, defaults to readiness phase. If phases includes "all", runs all phases.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chainsaw executes Chainsaw-style assertions against a live Kubernetes cluster.
|
Package chainsaw executes Chainsaw-style assertions against a live Kubernetes cluster. |