kubectlexec

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package kubectlexec is an example sandbox implementation that runs each exec-hook invocation inside a sidecar container in an existing Kubernetes pod via `kubectl exec -i -- <cmd>`. The pattern fits deployments where PromptKit runs in-cluster with a long-lived hooks sidecar that has the hook runtime (Python, Node, etc.) and scripts baked in.

This is reference/example code — not imported by PromptKit core. Register via sdk.WithSandboxFactory or sandbox.RegisterFactory, or construct one directly and set it on ExecHookConfig.Sandbox.

Configuration:

mode: kubectl_exec
pod: my-agent-pod              # required
namespace: default             # optional; maps to -n
container: hooks               # optional; maps to -c
kubeconfig: /etc/kube.yaml     # optional; maps to --kubeconfig
context: prod                  # optional; maps to --context
extra_args: [--request-timeout=5s]

Index

Constants

View Source
const ModeName = "kubectl_exec"

ModeName is the identifier under which this backend registers with sandbox.RegisterFactory.

Variables

This section is empty.

Functions

func Factory

func Factory(name string, cfg map[string]any) (sandbox.Sandbox, error)

Factory is a sandbox.Factory compatible with RuntimeConfig-based resolution.

Types

type Config

type Config struct {
	// Pod is the target pod. Required.
	Pod string
	// Namespace maps to `-n <value>`. Empty means don't pass the flag
	// (kubectl falls back to the current-context default).
	Namespace string
	// Container maps to `-c <value>`. Empty means don't pass the flag.
	Container string
	// Kubeconfig maps to `--kubeconfig=<value>`.
	Kubeconfig string
	// Context maps to `--context=<value>`.
	Context string
	// ExtraArgs are extra `kubectl exec` flags inserted after the
	// standard ones and before the `--` command separator.
	ExtraArgs []string
	// KubectlPath overrides the `kubectl` binary name. Empty uses
	// `kubectl` resolved from PATH.
	KubectlPath string
}

Config configures the kubectl-exec backend.

type Sandbox

type Sandbox struct {
	// contains filtered or unexported fields
}

Sandbox runs exec-hook commands via `kubectl exec` in an existing pod.

func New

func New(cfg Config) *Sandbox

New constructs a Sandbox from a Config.

func NewNamed

func NewNamed(name string, cfg Config) *Sandbox

NewNamed is like New but lets the caller override the sandbox name.

func (*Sandbox) Name

func (s *Sandbox) Name() string

Name returns the sandbox's name.

func (*Sandbox) Spawn

func (s *Sandbox) Spawn(ctx context.Context, req sandbox.Request) (sandbox.Response, error)

Spawn builds a kubectl exec argv and delegates to the inner direct sandbox. Layout:

kubectl [--kubeconfig=...] [--context=...] exec -i \
        [-n <ns>] [-c <container>] <extra...> <pod> -- <cmd> <args...>

Jump to

Keyboard shortcuts

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