k8s

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 42 Imported by: 1 module, 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

Index

Constants

View Source
const (
	ActivitySourceExec        = "exec"
	ActivitySourceLogs        = "logs"
	ActivitySourcePortForward = "port-forward"
)

Activity sources the backend accepts for a heartbeat.

View Source
const ActivityHeartbeatInterval = 2 * time.Minute

ActivityHeartbeatInterval is how often a long-running session tells the backend the environment is still in use, so it is not stopped mid-session for having no recent visit. It is short so that one failed report can't end a session under a short timeout. The backend records one audit event per five minutes however often it hears from a session.

Variables

This section is empty.

Functions

func CheckPluginToken added in v1.12.0

func CheckPluginToken() error

CheckPluginToken refuses an API token other than the one connect used, when this process runs as a credential plugin (tokenHashEnv set).

func ExecCredential added in v1.12.0

func ExecCredential(c client.Client, envID string, now time.Time) ([]byte, error)

ExecCredential fetches the environment's kubeconfig from Shipyard and returns its token as a client.authentication.k8s.io/v1 ExecCredential, the answer a kubeconfig's exec plugin prints. When the token says when it expires (a JWT exp claim), the credential expires a little before that, so clients ask again in time; a token without one (older clusters' tokens never expire) is kept until the API server refuses it.

func StartActivityHeartbeat added in v1.11.0

func StartActivityHeartbeat(ctx context.Context, c client.Client, envID, source string, interval time.Duration) (stop func())

StartActivityHeartbeat reports activity on an environment every interval until ctx is done, stop is called or activityMaxSession passes. The first report goes out after one interval: fetching the kubeconfig already counts as the start of the session.

A failed report must never end the session. It is logged, and repeated failures warn the user once. A report can't be cancelled, so stop waits for one in flight only briefly: the session is over by then, and it must not be held up by a stalled API.

func StartInputHeartbeat added in v1.11.0

func StartInputHeartbeat(ctx context.Context, c client.Client, envID, source string, interval time.Duration, input *InputActivity) (stop func())

StartInputHeartbeat is StartActivityHeartbeat for a session that only counts as activity while it has input: it skips an interval that had none.

Types

type Client added in v1.7.0

type Client struct {
	Path string
}

Client points at the environment's kubeconfig saved in ~/.shipyard, for tools such as telepresence that need a file rather than a parsed config.

func NewConfig added in v1.7.0

func NewConfig(c client.Client, envid string, plugin CredentialPlugin) (*Client, error)

NewConfig saves the environment's kubeconfig to the shared ~/.shipyard/kubeconfig and returns its path. Only telepresence uses it; logs, exec and port-forward keep the config in memory (see New).

The saved kubeconfig holds no token: telepresence runs plugin for one, and again as each expires. Tokens on current clusters last an hour, and telepresence keeps making API requests for as long as it is connected.

type ContainerState added in v1.10.0

type ContainerState struct {
	Pod       string
	Container string
	// Init is set when Container is an init container
	Init         bool
	Ready        bool
	RestartCount int32
	// Reason and ExitCode describe the last time the container stopped, if it has
	Reason   string
	ExitCode *int32
}

ContainerState describes a service container's restarts and how it last stopped.

type CredentialPlugin added in v1.12.0

type CredentialPlugin struct {
	Command string
	Args    []string
	Env     map[string]string
}

CredentialPlugin is the command a kubeconfig runs to get a fresh token for an environment: this CLI, with the arguments that reach `telepresence credential` and the settings it needs (org, config file, API URL). Env holds no secrets.

func TelepresenceCredentialPlugin added in v1.12.0

func TelepresenceCredentialPlugin(envID, org string) (CredentialPlugin, error)

TelepresenceCredentialPlugin is the plugin a telepresence kubeconfig for envID runs: this executable's hidden `telepresence credential` command, with the org, config file and API URL this run uses. The plugin runs later, in telepresence's daemon, whose environment may not match this one (it may have started under another mode). So the API URL is always pinned; a token read from the config file is read from there again, not from the daemon's SHIPYARD_API_TOKEN; and the plugin checks it holds the same token as this run (tokenHashEnv), so it never sends one endpoint's token to another.

type ExecOutput added in v1.9.0

type ExecOutput struct {
	Stdout    string
	Stderr    string
	ExitCode  int
	Truncated bool
}

ExecOutput is what a non-interactive command wrote before it finished.

type InputActivity added in v1.11.0

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

InputActivity records whether a session has had input since the last report. An exec session counts as activity only while someone is using it, as in the web terminal, so a forgotten shell does not keep an environment running.

func (*InputActivity) Reader added in v1.11.0

func (a *InputActivity) Reader(r io.Reader) io.Reader

Reader returns r, noting each read that returns data.

type Service

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

func New

func New(c client.Client, id string, svc *types.Service) (*Service, error)

func (*Service) Exec

func (c *Service) Exec(args []string, input *InputActivity) error

func (*Service) ExecCapture added in v1.9.0

func (c *Service) ExecCapture(ctx context.Context, args []string, maxBytes int) (ExecOutput, error)

ExecCapture runs a command in the service's pod and returns what it wrote.

This is Exec without the terminal: no stdin is attached and no TTY is requested, so it fits a caller that has one request and wants one response, such as the MCP server. Dropping the TTY also keeps stdout and stderr on separate streams, which a TTY merges.

A command that exits non-zero is not an error here: its output and exit code are the answer. An error means the exec never ran or the stream broke.

maxBytes caps each stream; zero or less means no cap. Cap what you hand to a model: `cat` on a large file otherwise fills its context with one tool result.

func (*Service) GetLogsAsString added in v1.8.0

func (c *Service) GetLogsAsString(follow bool, tail int64) (string, error)

GetLogsAsString returns logs as a string instead of printing them This is used by the MCP logs service to capture log output

func (*Service) GetPreviousLogsAsString added in v1.10.0

func (c *Service) GetPreviousLogsAsString(tail int64) (string, error)

GetPreviousLogsAsString returns the logs of the container's previous run, the one that crashed.

func (*Service) Logs

func (c *Service) Logs(follow bool, tail int64) error

func (*Service) PortForward

func (c *Service) PortForward(ports []string) error

func (*Service) UseCrashedPod added in v1.10.0

func (c *Service) UseCrashedPod() ContainerState

UseCrashedPod switches this Service (logs, exec and port-forward alike) to the pod and container most likely to explain a crash, which may be an init container or a sidecar, and returns that container's state. Use a fresh Service for anything else.

Jump to

Keyboard shortcuts

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