Documentation
¶
Overview ¶
Package runtime runs sprites as containers for spritzer's container exec mode. A Backend creates, lists and deletes one container per sprite and execs commands in it. Two backends exist: Docker (the Engine API over its socket) and Kubernetes (one pod per sprite, in spritzer's namespace).
Everything above a backend goes through Exec. The in-sprite agent (internal/agent) turns an exec into a socket connection or a file operation, so a backend needs no port forwarding and no network path into the sprite.
Index ¶
- Constants
- Variables
- func Dial(ctx context.Context, b Backend, name, target string) (net.Conn, error)
- func Run(ctx context.Context, b Backend, name string, argv []string, input []byte) (stdout, stderr []byte, code int, err error)
- func ValidName(name string) error
- type Backend
- type Config
- type Docker
- func (d *Docker) Create(ctx context.Context, name string) error
- func (d *Docker) Delete(ctx context.Context, name string) error
- func (d *Docker) Exec(ctx context.Context, name string, argv []string, stdin bool) (Process, error)
- func (d *Docker) Kind() string
- func (d *Docker) List(ctx context.Context) ([]string, error)
- type Kubernetes
- func (k *Kubernetes) Create(ctx context.Context, name string) error
- func (k *Kubernetes) Delete(ctx context.Context, name string) error
- func (k *Kubernetes) Exec(ctx context.Context, name string, argv []string, stdin bool) (Process, error)
- func (k *Kubernetes) Kind() string
- func (k *Kubernetes) List(ctx context.Context) ([]string, error)
- func (k *Kubernetes) Namespace() string
- type Process
Constants ¶
const ( BinDir = "/.sprite/bin" AgentBinary = "/.sprite/bin/spritzer" AgentSocket = "/.sprite/api.sock" )
Well-known paths inside every sprite. The agent volume is mounted at BinDir.
const ( LabelManagedBy = "app.kubernetes.io/managed-by" LabelSprite = "spritzer.intentius.io/sprite" ManagedBy = "spritzer" )
Labels every sprite container or pod carries.
Variables ¶
var ErrNotFound = errors.New("sprite container not found")
ErrNotFound is a sprite the backend has no container for.
Functions ¶
func Dial ¶
Dial runs `spritzer x-relay target` in the sprite and returns the exec as a net.Conn: writes go to the relay's stdin, reads come from its stdout.
Types ¶
type Backend ¶
type Backend interface {
// Kind is "docker" or "kubernetes".
Kind() string
// Create starts a sprite container and returns once its agent answers.
// Creating a sprite that already exists is not an error.
Create(ctx context.Context, name string) error
// Delete removes the container and returns once it is gone.
Delete(ctx context.Context, name string) error
// List returns the names of every sprite container the backend holds.
List(ctx context.Context) ([]string, error)
// Exec starts argv in the sprite. With stdin false the process's stdin is
// closed from the start.
Exec(ctx context.Context, name string, argv []string, stdin bool) (Process, error)
}
Backend is one container runtime.
type Config ¶
type Config struct {
// SpriteImage is the image every sprite runs.
SpriteImage string
// AgentImage is spritzer's own image, which carries the Linux agent binary
// copied into each sprite.
AgentImage string
// CreateTimeout bounds a create, image pulls included.
CreateTimeout time.Duration
}
Config is what both backends need.
type Docker ¶
type Docker struct {
// contains filtered or unexported fields
}
Docker runs each sprite as a container named spritzer-<name>, talking to the Engine API on a unix socket (DOCKER_HOST=unix://..., else /var/run/docker.sock). The agent binary reaches sprites through a named volume, filled once at startup by running spritzer's own image with `agent-install`, and mounted read-only at /.sprite/bin. Containers run with Docker's init, so the agent is not PID 1 and orphans are reaped.
type Kubernetes ¶
type Kubernetes struct {
// contains filtered or unexported fields
}
Kubernetes runs each sprite as a pod named sprite-<name> in one namespace, with the in-cluster service account. An init container from spritzer's own image copies the agent into an emptyDir mounted at /.sprite/bin; the sprite container runs `spritzer agent` from there. shareProcessNamespace makes the pause container PID 1, which reaps orphans.
The service account needs, in that namespace: pods create/get/list/delete and pods/exec create/get.
func NewKubernetes ¶
func NewKubernetes(cfg Config, namespace string) (*Kubernetes, error)
NewKubernetes reads the in-cluster config. namespace overrides the service account's own.
func (*Kubernetes) Create ¶
func (k *Kubernetes) Create(ctx context.Context, name string) error
Create implements Backend.
func (*Kubernetes) Delete ¶
func (k *Kubernetes) Delete(ctx context.Context, name string) error
Delete implements Backend, and returns once the pod is gone.
func (*Kubernetes) Exec ¶
func (k *Kubernetes) Exec(ctx context.Context, name string, argv []string, stdin bool) (Process, error)
Exec implements Backend over the pods/exec WebSocket (v5.channel.k8s.io, which can close stdin; v4 as a fallback, which cannot).
func (*Kubernetes) List ¶
func (k *Kubernetes) List(ctx context.Context) ([]string, error)
List implements Backend.
func (*Kubernetes) Namespace ¶
func (k *Kubernetes) Namespace() string
Namespace is where sprite pods live.
type Process ¶
type Process interface {
Stdin() io.WriteCloser
Stdout() io.Reader
Stderr() io.Reader
Wait() (int, error)
// Close abandons the stream. It does not kill the process inside the
// sprite; see agent.Kill.
Close() error
}
Process is a running exec. Stdout and Stderr must both be read, or the stream stalls. Wait returns the exit code once both have reached EOF.