Documentation
¶
Index ¶
- Constants
- func CheckPluginToken() error
- func ExecCredential(c client.Client, envID string, now time.Time) ([]byte, error)
- func StartActivityHeartbeat(ctx context.Context, c client.Client, envID, source string, ...) (stop func())
- func StartInputHeartbeat(ctx context.Context, c client.Client, envID, source string, ...) (stop func())
- type Client
- type ContainerState
- type CredentialPlugin
- type ExecOutput
- type InputActivity
- type Service
- func (c *Service) Exec(args []string, input *InputActivity) error
- func (c *Service) ExecCapture(ctx context.Context, args []string, maxBytes int) (ExecOutput, error)
- func (c *Service) GetLogsAsString(follow bool, tail int64) (string, error)
- func (c *Service) GetPreviousLogsAsString(tail int64) (string, error)
- func (c *Service) Logs(follow bool, tail int64) error
- func (c *Service) PortForward(ports []string) error
- func (c *Service) UseCrashedPod() ContainerState
Constants ¶
const ( ActivitySourceExec = "exec" ActivitySourceLogs = "logs" ActivitySourcePortForward = "port-forward" )
Activity sources the backend accepts for a heartbeat.
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
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
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
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
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.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) ExecCapture ¶ added in v1.9.0
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
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
GetPreviousLogsAsString returns the logs of the container's previous run, the one that crashed.
func (*Service) PortForward ¶
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.