kube

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package kube talks to the apiserver and projects what it finds into model.Snapshot.

Everything here is read-only. That is not a convention: TestNoMutatingVerbs walks this package's AST and fails on any call to a mutating client verb. v0.1 runs under a developer kubeconfig with full cluster-admin, so RBAC will not hold that line for us — the binary has to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderLogs added in v0.1.2

func RenderLogs(b *model.LogBundle) string

RenderLogs formats a bundle for a human or a model to read.

Types

type AmbiguousError

type AmbiguousError struct {
	Query      string
	Candidates []Ref
}

AmbiguousError lists the candidates when a fuzzy name matches more than one workload. Returning the choices beats picking one: during an incident, silently diagnosing the wrong workload costs more than one extra round-trip.

func (*AmbiguousError) Error

func (e *AmbiguousError) Error() string

type Client

type Client struct {
	Typed   kubernetes.Interface
	Metrics metricsv.Interface
	Dynamic dynamic.Interface
	Context string // resolved context name, for audit logging
	// contains filtered or unexported fields
}

Client bundles the three typed clients a gather needs, plus the call budget they share.

func New

func New(opts Options) (*Client, error)

New builds a Client from a kubeconfig, falling back to in-cluster config.

func (*Client) Calls

func (c *Client) Calls() int64

Calls reports apiserver requests spent so far, for the audit log.

func (*Client) Gather

func (c *Client) Gather(ctx context.Context, ref Ref) (*model.Snapshot, error)

Gather collects everything needed to diagnose one workload and projects it into a Snapshot.

Failures are recorded in Snapshot.Degraded rather than returned. During an incident a partial diagnosis beats no diagnosis — but detectors must consult Snapshot.Missing and dock their confidence, so "we could not see the metrics API" never masquerades as "memory looks fine".

func (*Client) Logs added in v0.1.2

func (c *Client) Logs(ctx context.Context, ref Ref, opts LogOptions) (*model.LogBundle, error)

Logs fetches container output for a workload, choosing the pod, container and instance itself.

The choices are the product. Anyone can call GetLogs; knowing that a crashlooping container's CURRENT instance has produced nothing and the interesting output is in the PREVIOUS one is the part that saves an incident's worth of thrash.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, query, namespace string) (Ref, error)

Resolve turns a fuzzy query into exactly one Ref.

Accepts "checkout", "checkout-api", "deploy/checkout-api", or "deployment/checkout-api". Matching is tiered — exact name first, then prefix, then substring — and stops at the first tier that produces hits, so an exact name is never made ambiguous by an unrelated substring match.

func (*Client) WithTimeout

func (c *Client) WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

WithTimeout derives the per-invocation deadline. Callers must use the returned context for every apiserver call so a slow cluster degrades the snapshot instead of hanging the MCP session.

type LogOptions added in v0.1.2

type LogOptions struct {
	Container string // empty means auto-select
	Previous  *bool  // nil means decide from the container's state
	TailLines int64  // 0 means a sensible default
	SinceSecs int64  // 0 means no lower bound
	Budget    int    // token budget; 0 means the default
}

LogOptions controls log selection. Every field is optional; the zero value means "decide for me", which is the intended path.

type Options

type Options struct {
	Kubeconfig string        // path; empty means the standard loading rules, then in-cluster
	Context    string        // kubeconfig context name; empty means current-context
	Timeout    time.Duration // per-invocation deadline for the whole gather
	MaxCalls   int64         // hard cap on apiserver requests per invocation
}

Options configures cluster access and the blast-radius limits on a single tool invocation.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions are deliberately conservative. A diagnostic tool that DoSes the control plane during an incident is a career-limiting artifact.

type Ref

type Ref struct {
	Kind      string // Deployment | StatefulSet | DaemonSet | Rollout
	Name      string
	Namespace string
}

Ref identifies a workload controller.

func (Ref) String

func (r Ref) String() string

Jump to

Keyboard shortcuts

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