Documentation
¶
Overview ¶
Package kube talks to the Kubernetes API directly over HTTPS, from one kubeconfig context, without client-go. It covers what komando's cluster commands need: discovery, get/list, logs, patch, server-side apply, and exec and port-forward over WebSocket (stream.go).
Index ¶
- Constants
- Variables
- func Nearest(w string, known []string) string
- type APIError
- type AuthInfo
- type Client
- func (c *Client) Do(ctx context.Context, method, path string, q url.Values, body []byte, ...) ([]byte, error)
- func (c *Client) Exec(ctx context.Context, o ExecOptions) error
- func (c *Client) Get(ctx context.Context, path string, q url.Values, v any) error
- func (c *Client) PortForward(ctx context.Context, namespace, pod string, port int, conn net.Conn) error
- func (c *Client) Resource(ctx context.Context, name string) (ResourceType, error)
- func (c *Client) ResourceFor(ctx context.Context, apiVersion, kind string) (ResourceType, error)
- func (c *Client) Resources(ctx context.Context) ([]ResourceType, error)
- func (c *Client) Stream(ctx context.Context, path string, q url.Values) (io.ReadCloser, error)
- func (c *Client) Table(ctx context.Context, path string, q url.Values) (*Table, error)
- func (c *Client) Watch(ctx context.Context, path string, q url.Values) (io.ReadCloser, error)
- type Cluster
- type Config
- type Context
- type Dialer
- type ExecAuth
- type ExecOptions
- type ExitError
- type NamedCluster
- type NamedContext
- type NamedUser
- type PluginError
- type ResourceType
- type Table
- type TermSize
- type UnknownKindError
Constants ¶
const DialTimeout = 30 * time.Second
DialTimeout limits a direct connection to the API server; without it an address that never answers waits for the system's own limit (75 s and more).
Variables ¶
var ErrUncheckedLogin = errors.New("a login made from this computer's AWS or Google Cloud login goes to a cluster only over https with its certificate checked: take insecure-skip-tls-verify out of the kubeconfig (certificate-authority-data trusts the cluster's CA) and import it again")
ErrUncheckedLogin stops a token made from this computer's cloud login on its way to a server over plain http, or one whose certificate is not checked: the token is good for the cloud account, not only this cluster.
Functions ¶
Types ¶
type AuthInfo ¶
type AuthInfo struct {
ClientCertificate string `yaml:"client-certificate,omitempty"`
ClientCertificateData string `yaml:"client-certificate-data,omitempty"`
ClientKey string `yaml:"client-key,omitempty"`
ClientKeyData string `yaml:"client-key-data,omitempty"`
Token string `yaml:"token,omitempty"`
TokenFile string `yaml:"tokenFile,omitempty"`
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Exec *ExecAuth `yaml:"exec,omitempty"`
}
type Client ¶
type Client struct {
Base *url.URL
Namespace string
// Env is the environment a credential plugin runs with (the
// command's); nil is this process's.
Env []string
// contains filtered or unexported fields
}
Client calls one cluster's API.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, path string, q url.Values, body []byte, contentType string) ([]byte, error)
Do sends a request; path is relative to the server ("/api/v1/...").
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, o ExecOptions) error
Exec runs a command in a container and waits for it. A non-zero exit comes back as *ExitError.
func (*Client) PortForward ¶
func (c *Client) PortForward(ctx context.Context, namespace, pod string, port int, conn net.Conn) error
PortForward connects conn to port on a pod, until either side closes. One WebSocket carries one connection.
func (*Client) Resource ¶
Resource finds a ResourceType by a name people type: "pods", "pod", "po", "deploy" or "deployments.apps".
func (*Client) ResourceFor ¶
ResourceFor finds the ResourceType of an object (apiVersion + kind).
func (*Client) Resources ¶
func (c *Client) Resources(ctx context.Context) ([]ResourceType, error)
Resources lists every resource type the cluster serves, once each.
func (*Client) Stream ¶
Stream sends a GET and returns the body as it arrives (follow=true logs). The caller closes it.
type Cluster ¶
type Cluster struct {
Server string `yaml:"server"`
CertificateAuthority string `yaml:"certificate-authority,omitempty"`
CertificateAuthorityData string `yaml:"certificate-authority-data,omitempty"`
InsecureSkipTLSVerify bool `yaml:"insecure-skip-tls-verify,omitempty"`
TLSServerName string `yaml:"tls-server-name,omitempty"`
ProxyURL string `yaml:"proxy-url,omitempty"`
}
type Config ¶
type Config struct {
CurrentContext string `yaml:"current-context"`
Clusters []NamedCluster `yaml:"clusters"`
Users []NamedUser `yaml:"users"`
Contexts []NamedContext `yaml:"contexts"`
}
Config is the part of a kubeconfig komando uses.
func Load ¶ added in v0.12.0
Load reads kubeconfig files the way kubectl reads a KUBECONFIG list: the first file that names a context, cluster or user wins, and so does the first current-context. Relative file paths in a file (a minikube or kind certificate) count from that file's folder, not the current one. read reads one file; "-" is stdin and keeps paths as they are.
func (*Config) ContextNames ¶
ContextNames lists the context names in file order.
type Context ¶
Context is one resolved kubeconfig context.
func (*Context) CloudLogin ¶ added in v0.15.0
CloudLogin is the plugin whose token komando makes itself from this computer's AWS or Google Cloud login (Builtin), or nil. No program runs, but a credential of this computer goes to the context's server.
func (*Context) Plugin ¶ added in v0.3.0
Plugin is the credential plugin that logging in to this context runs as a program on this computer, or nil: none, a static token, or one of the plugins komando makes the token for itself (Builtin).
func (*Context) Standalone ¶
Standalone returns a kubeconfig with only this context, files read into the *-data fields, so it can live in the vault and travel. The files the kubeconfig names (CA, client certificate and key, token) are read with read, so the caller's rules for local files apply to them as they do to the kubeconfig itself.
type ExecAuth ¶
type ExecAuth struct {
APIVersion string `yaml:"apiVersion,omitempty"`
Command string `yaml:"command"`
Args []string `yaml:"args,omitempty"`
Env []struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
} `yaml:"env,omitempty"`
// InstallHint is what the kubeconfig says to do when Command is not
// installed (kubectl prints it too).
InstallHint string `yaml:"installHint,omitempty"`
// SearchPath, when set, is the PATH the program runs with instead of
// the caller's (the cli sets it for a program a person trusted, so an
// AI agent's PATH does not pick the program's helpers); the variables
// that steer a program are then left out too (pluginEnv).
SearchPath string `yaml:"-"`
// Check, when set, runs right before the program starts; an error
// stops the login (the cli checks again that the file is the one a
// person trusted).
Check func() error `yaml:"-"`
}
ExecAuth is a credential plugin (aws eks get-token, gke-gcloud-auth-plugin, ...).
type ExecOptions ¶
type ExecOptions struct {
Namespace, Pod, Container string
Command []string
Stdin io.Reader
Stdout, Stderr io.Writer
TTY bool
Resize <-chan TermSize // only with TTY
}
ExecOptions describe one command in a container.
type ExitError ¶
type ExitError struct{ Code int }
ExitError is a command that ended with a non-zero exit code.
type NamedCluster ¶ added in v0.12.0
type NamedContext ¶ added in v0.12.0
type PluginError ¶ added in v0.13.0
type PluginError struct {
Command string
InstallHint string
Missing bool
Detail string // the plugin's own words (stderr), or why its output was no token
}
PluginError is a credential plugin that could not log in: its program is not on this computer (Missing), it failed, or it printed no token.
func (*PluginError) Error ¶ added in v0.13.0
func (e *PluginError) Error() string
type ResourceType ¶
type ResourceType struct {
Path string // "/api/v1" or "/apis/apps/v1"
Name string // plural: deployments
Kind string
Namespaced bool
ShortNames []string
}
func (ResourceType) APIVersion ¶
func (r ResourceType) APIVersion() string
APIVersion is what objects of r carry in apiVersion ("v1", "apps/v1").
func (ResourceType) Group ¶
func (r ResourceType) Group() string
Group is the API group of r ("" for the core group, "apps", ...).
func (ResourceType) IsNamespaced ¶
func (r ResourceType) IsNamespaced() bool
func (ResourceType) KindName ¶
func (r ResourceType) KindName() string
func (ResourceType) ObjectPath ¶
func (r ResourceType) ObjectPath(ns, name string) string
ObjectPath is the API path of a ResourceType (all namespaces when ns is "").
func (ResourceType) Version ¶
func (r ResourceType) Version() string
Version is r's API version ("v1", ...).
type Table ¶
type Table struct {
ColumnDefinitions []struct {
Name string `json:"name"`
Priority int `json:"priority"`
} `json:"columnDefinitions"`
Rows []struct {
Cells []any `json:"cells"`
Object struct {
Metadata struct {
Namespace string `json:"namespace"`
} `json:"metadata"`
} `json:"object"`
} `json:"rows"`
}
Table is the server-side table the API prints for a list or an object, the same columns kubectl shows.
type TermSize ¶
type TermSize struct{ Width, Height uint16 }
TermSize is a terminal's size in characters.
type UnknownKindError ¶
UnknownKindError is a kind the cluster does not serve. APIVersion is set for an object's apiVersion and kind (ResourceFor).
func (*UnknownKindError) Error ¶
func (e *UnknownKindError) Error() string