query

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package query evaluates a JSONPath expression against every captured object in an archive, across all resource types and namespaces, at a chosen point in time.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the version of the `kshrk query -o json` output shape, shared by Result (JSONPath mode) and TextResult (--text/--regex mode).

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {
	Path      string          `json:"path"`
	Group     string          `json:"group,omitempty"`
	Version   string          `json:"version,omitempty"`
	Resource  string          `json:"resource,omitempty"`
	Namespace string          `json:"namespace,omitempty"`
	Name      string          `json:"name"`
	Value     json.RawMessage `json:"value"`
}

Match is one JSONPath result found on one captured object.

type Options

type Options struct {
	// Expression is a kubectl-style JSONPath template, e.g. "{.spec.containers[*].image}".
	Expression string
	// At selects the snapshot to query. Zero means the latest captured state.
	At time.Time
	// Resource limits the query to one resource type, e.g. "pods". Empty means all.
	Resource string
	// Namespace limits the query to one namespace. Empty means all.
	Namespace string
}

Options configures a Run.

type Result

type Result struct {
	SchemaVersion int     `json:"schema_version"`
	Matches       []Match `json:"matches"`
}

Result is the full set of matches for one query.

func Run

func Run(store *store.CaptureStore, opts Options) (*Result, error)

Run evaluates opts.Expression against every captured object in store at the resolved snapshot, returning one Match per JSONPath result found on an object — including zero-value results like "" or null, since those mean the field exists. Objects that don't have the queried field at all produce no results (via AllowMissingKeys) and are skipped, not treated as errors.

type TextMatch

type TextMatch struct {
	Path      string `json:"path"`
	Group     string `json:"group,omitempty"`
	Version   string `json:"version,omitempty"`
	Resource  string `json:"resource,omitempty"`
	Namespace string `json:"namespace,omitempty"`
	Name      string `json:"name"`
	// Field is the JSON field path of the matched string, e.g.
	// "metadata.annotations.note" or "spec.containers[0].image". A map key
	// that isn't a simple identifier (common for annotations/labels, e.g.
	// "kubectl.kubernetes.io/last-applied-configuration") is bracket-quoted:
	// metadata.annotations["kubectl.kubernetes.io/last-applied-configuration"].
	// Empty for log matches.
	Field string `json:"field,omitempty"`
	// Log is true when this match came from a captured pod log rather than
	// an object body. Container may still be empty on a Log match — legacy
	// archives could store a single log record with no ?container= query
	// param — so Log, not "Container != \"\"", is the reliable signal that
	// this is a log match.
	Log bool `json:"log,omitempty"`
	// Container and Previous are set only for matches found in a captured pod
	// log (Log == true); Container may be empty (see Log).
	Container string `json:"container,omitempty"`
	Previous  bool   `json:"previous,omitempty"`
	// Snippet is the matched text with surrounding context.
	Snippet string `json:"snippet"`
}

TextMatch is one substring/regex match found in a captured object body or pod log.

type TextOptions

type TextOptions struct {
	// Pattern is the substring (default) or regular expression to search for.
	Pattern string
	// Regex treats Pattern as a Go regular expression instead of a plain substring.
	Regex bool
	// At selects the snapshot to search. Zero means the latest captured state.
	At time.Time
	// Resource limits the search to one resource type, e.g. "pods". Empty means all.
	Resource string
	// Namespace limits the search to one namespace. Empty means all.
	Namespace string
}

TextOptions configures a SearchText.

type TextResult

type TextResult struct {
	SchemaVersion int         `json:"schema_version"`
	Matches       []TextMatch `json:"matches"`
}

TextResult is the full set of matches for one full-text search.

func SearchText

func SearchText(store *store.CaptureStore, opts TextOptions) (*TextResult, error)

SearchText finds opts.Pattern across every captured object body and pod log in store at the resolved snapshot.

Jump to

Keyboard shortcuts

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