check

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTraceDuration is the default duration in seconds for trace checks.
	DefaultTraceDuration = 30
)

Variables

This section is empty.

Functions

func FormatResults

func FormatResults(results []NodeResult) (output string, hasFailure bool)

FormatResults produces a consistent human-readable output and returns whether any check failed.

func Register

func Register(c Check)

Register adds a check to the global registry. Typically called from init() in each check file.

Types

type Check

type Check interface {
	// Name returns the kebab-case identifier used as the subcommand name.
	Name() string
	// Description returns a short description for --help.
	Description() string
	// Mode returns whether this is a verify (point-in-time) or trace (duration) check.
	Mode() Mode
	// Command returns the shell command(s) to execute on the node.
	// For trace checks, the framework substitutes {{.Duration}} with the
	// user-specified --duration value in seconds.
	Command() string
	// Parse interprets the runtime result and returns a check Result.
	Parse(res *pkgruntime.RunResult) (*Result, error)
}

Check is the interface every check must implement. The framework handles runtime selection, node targeting, cluster fan-out, cobra wiring, and result reporting. Contributors only implement this.

func All

func All() []Check

All returns all registered checks.

func ByMode

func ByMode(m Mode) []Check

ByMode returns checks filtered by mode.

type IGCheck

type IGCheck struct {
	// GadgetImage is the gadget to run (e.g. "trace_dns", "trace_tcpretrans").
	GadgetImage string
	// OutputMode is the output format flag (default: "json").
	OutputMode string
	// Filters is a list of filter expressions joined by comma for --filter.
	// It is recommended to use the filter to limit the data volume since
	// azure-api runtime only has 4KB of output buffer.
	Filters []string
	// ExtraArgs are additional arguments appended after the filter flags.
	ExtraArgs []string
}

IGCheck provides common command-building logic for checks that use the ig binary. Embed this in a check struct to automatically generate the ig command string.

func (*IGCheck) IGCommand

func (ig *IGCheck) IGCommand() string

IGCommand builds the ig command string with the standard flags. The returned command uses {{.Duration}} as a placeholder for the trace timeout.

type K8s

type K8s struct {
	Namespace string `json:"namespace"`
	PodName   string `json:"podName"`
}

K8s holds Kubernetes metadata from ig event output.

func (K8s) FormatPod

func (k K8s) FormatPod() string

FormatPod returns "namespace/pod" or empty string if no k8s context.

type Mode

type Mode int

Mode describes how a check executes on a node.

const (
	// ModeVerify runs a command once and interprets the result as pass/fail.
	ModeVerify Mode = iota
	// ModeTrace runs a command for a specified duration, collecting events.
	ModeTrace
)

type NodeResult

type NodeResult struct {
	NodeName string
	Result   *Result
	Err      error
}

NodeResult holds the outcome of running a check on a single node.

func RunOnNode

func RunOnNode(ctx context.Context, c Check, rt pkgruntime.Runtime, nodeName string, timeout int, duration int) (*NodeResult, error)

RunOnNode executes a check on a single node using the given runtime.

func RunOnNodes

func RunOnNodes(ctx context.Context, c Check, nodes []string, factory RuntimeFactory, timeout int, duration int) []NodeResult

RunOnNodes executes a check across multiple nodes in parallel.

type Result

type Result struct {
	Success bool
	Message string // human-readable one-line summary
	Details string // optional verbose output
}

Result represents the outcome of a single check on one node.

type RuntimeFactory

type RuntimeFactory func(nodeName string) (pkgruntime.Runtime, error)

RuntimeFactory creates a runtime for a given node name. This allows the runner to be decoupled from the runtime construction details.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL