exec

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exec runs an interactive shell in a container, proxied through this process.

This is the first genuinely destructive capability kubeside has, which is why the guardrails and the permission resolver landed before it. Nothing here decides whether a session may start: the caller checks the environment's write policy and asks the cluster for pods/exec, and only then opens a session.

The browser never talks to an apiserver. Keystrokes arrive over the local websocket, cross into a SPDY stream here, and the credentials stay in this process, exactly as every other read does.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCommand = []string{"/bin/sh", "-c", "command -v bash >/dev/null 2>&1 && exec bash || exec sh"}

DefaultCommand is the shell to run when nobody named one.

bash first, sh second, in one invocation: an alpine container has no bash, and failing on it would send the developer back to a terminal for the one thing they came here to avoid.

The test has to come before the exec, not after it. A failed exec replaces the shell with nothing and exits 127; it never reaches an "||" branch, which is precisely how the first version of this failed against an alpine image.

Functions

func CommandFor

func CommandFor(requested []string) []string

CommandFor returns what to run.

Types

type Executor

type Executor interface {
	Run(ctx context.Context, t Target, streams Streams) error
}

Executor runs one session against a cluster. Keeping it an interface lets the plumbing be tested without an apiserver, which matters more here than anywhere else in the product.

type KubeExecutor

type KubeExecutor struct {
	// RESTConfig returns the config for one context, which is where credential
	// plugins run.
	RESTConfig func(contextName string) (*rest.Config, error)
}

KubeExecutor runs the session against a cluster, the same mechanism kubectl exec uses. Credentials stay in this process: the browser never holds one.

func (KubeExecutor) Run

func (k KubeExecutor) Run(ctx context.Context, t Target, streams Streams) error

Run streams until the shell exits or the context is cancelled.

type Session

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

Session is one running shell.

func New

func New(e Executor) *Session

New builds a session. Nothing runs until Start.

func (*Session) Close

func (s *Session) Close()

Close ends the session. Closing the tab must end the shell in the cluster, not leave one running with nobody attached.

func (*Session) Resize

func (s *Session) Resize(size Size)

Resize tells the shell how big its window is.

func (*Session) Start

func (s *Session) Start(ctx context.Context, t Target, onOutput func([]byte)) <-chan error

Start opens the session and streams output to onOutput until it ends.

The returned channel carries the session's ending: nil when the shell exited, or the reason it could not start. A blank terminal that never says why is the worst outcome available here.

func (*Session) Write

func (s *Session) Write(b []byte)

Write sends keystrokes to the container.

type Size

type Size struct {
	Cols uint16 `json:"cols"`
	Rows uint16 `json:"rows"`
}

Size is a terminal window. A shell that does not know it wraps every line wrongly, which makes a terminal unusable rather than merely ugly.

type Streams

type Streams struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	Resize <-chan Size
}

Streams is what an executor is handed.

type Target

type Target struct {
	Context   string
	Namespace string
	Pod       string
	Container string
	Command   []string
}

Target names exactly one container of one pod in one context. There is no shape here that could address two.

Jump to

Keyboard shortcuts

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