Documentation
¶
Overview ¶
Package chainsaw executes Chainsaw-style assertions against a live Kubernetes cluster. It supports two modes:
- Raw K8s resource YAML: Uses the chainsaw Go library for field matching (checks.Check).
- Chainsaw Test format (apiVersion: chainsaw.kyverno.io/v1alpha1): Invokes the chainsaw binary for full test execution (assert, script, wait, catch, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChainsawBinary ¶
type ChainsawBinary interface {
// RunTest executes chainsaw test against the given test directory.
// Returns whether all tests passed, the combined output, and any execution error.
RunTest(ctx context.Context, testDir string) (passed bool, output string, err error)
}
ChainsawBinary abstracts chainsaw CLI invocation for testability.
func NewChainsawBinary ¶
func NewChainsawBinary() ChainsawBinary
NewChainsawBinary creates a ChainsawBinary that invokes the chainsaw CLI. It resolves the binary path from PATH, falling back to /usr/local/bin/chainsaw.
type ComponentAssert ¶
type ComponentAssert struct {
// Name is the component name (e.g., "gpu-operator").
Name string
// AssertYAML is the raw Chainsaw assert file content.
AssertYAML string
}
ComponentAssert holds the data needed to run assertions for one component.
type ResourceFetcher ¶
type ResourceFetcher interface {
// Fetch retrieves a Kubernetes resource as an unstructured map.
Fetch(ctx context.Context, apiVersion, kind, namespace, name string) (map[string]interface{}, error)
}
ResourceFetcher abstracts fetching Kubernetes resources for testability.
func NewClusterFetcher ¶
func NewClusterFetcher(client dynamic.Interface, mapper meta.RESTMapper) ResourceFetcher
NewClusterFetcher creates a ResourceFetcher that queries a live Kubernetes cluster.
type Result ¶
type Result struct {
// Component is the component name.
Component string
// Passed indicates whether the assertion passed.
Passed bool
// Output contains diagnostic detail for failures.
Output string
// Error contains any error from executing the assertion.
Error error
}
Result holds the outcome of an assertion run for one component.
func Run ¶
func Run(ctx context.Context, asserts []ComponentAssert, timeout time.Duration, fetcher ResourceFetcher, opts ...RunOption) []Result
Run executes assertions for a set of components against live cluster resources. Components are run concurrently with bounded parallelism. For Chainsaw Test format YAML, the chainsaw binary is invoked directly. For raw K8s resource YAML, the Go library assertion engine is used.
type RunOption ¶
type RunOption func(*runConfig)
RunOption configures the behavior of Run.
func WithChainsawBinary ¶
func WithChainsawBinary(bin ChainsawBinary) RunOption
WithChainsawBinary sets the chainsaw binary used for Chainsaw Test format assertions.