kubectl

package
v0.11.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package kubectl provides helpers for running kubectl commands with the correct KUBECONFIG environment variable set. It centralises the pattern that was previously duplicated across network, x402, model, agent, and cmd/obol packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrClusterDown = errors.New("cluster appears to be stopped — run 'obol stack up' to start it")

ErrClusterDown indicates the Kubernetes API server is unreachable, typically because the k3d cluster is stopped.

Functions

func Apply

func Apply(binary, kubeconfig string, data []byte) error

Apply pipes the given data into kubectl apply -f -.

func ApplyOutput added in v0.8.0

func ApplyOutput(binary, kubeconfig string, data []byte) (string, error)

ApplyOutput pipes the given data into kubectl apply -f - and returns stdout.

func ApplyServerSideForceConflicts added in v0.9.0

func ApplyServerSideForceConflicts(binary, kubeconfig string, data []byte, fieldManager string) error

ApplyServerSideForceConflicts pipes the given data into kubectl apply --server-side --force-conflicts -f -. Use it only for narrow compatibility migrations where the caller has already decided which manager must own the restored fields.

func EnsureCluster

func EnsureCluster(cfg *config.Config) error

EnsureCluster verifies that the Kubernetes API server is reachable using the kubeconfig under cfg.ConfigDir. It checks the kubeconfig file exists, then actively probes the API server (kubectl is the source of truth — file presence alone does not mean ops will succeed). When the probe fails with a "cluster down"-shaped error AND the deployment looks like a k3d stack, it attempts ONE kubeconfig refresh via `k3d kubeconfig write` and retries the probe before giving up. This recovers from the common port-drift case after `k3d cluster stop && k3d cluster start`, where the kubeconfig on disk still points at the previous (now-defunct) API server port.

func FormatClusterDownError added in v0.8.0

func FormatClusterDownError(err error, args []string) string

FormatClusterDownError returns a contextual message for a cluster-down error based on the CLI arguments. Returns empty string if err is not ErrClusterDown.

func Output

func Output(binary, kubeconfig string, args ...string) (string, error)

Output executes kubectl and returns the captured stdout. Stderr is captured and included in the returned error on failure.

func Paths

func Paths(cfg *config.Config) (binary, kubeconfig string)

Paths returns the absolute paths to the kubectl binary and kubeconfig.

func PipeCommands added in v0.8.0

func PipeCommands(binary, kubeconfig string, args1, args2 []string) error

PipeCommands pipes the stdout of the first kubectl command into the stdin of the second. Both commands run with the correct KUBECONFIG. This is useful for patterns like "kubectl create --dry-run -o yaml | kubectl replace -f -" which avoid the 262KB annotation limit that kubectl apply imposes.

func Run

func Run(binary, kubeconfig string, args ...string) error

Run executes kubectl with the given arguments, inheriting stdout and capturing stderr. The error message includes stderr output on failure.

func RunSilent

func RunSilent(binary, kubeconfig string, args ...string) error

RunSilent executes kubectl without inheriting stdout. Stderr is captured and included in the returned error on failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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