runtime

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 22 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 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

View Source
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.

View Source
const (
	LabelManagedBy = "app.kubernetes.io/managed-by"
	LabelSprite    = "spritzer.intentius.io/sprite"
	ManagedBy      = "spritzer"
)

Labels every sprite container or pod carries.

Variables

View Source
var ErrNotFound = errors.New("sprite container not found")

ErrNotFound is a sprite the backend has no container for.

Functions

func Dial

func Dial(ctx context.Context, b Backend, name, target string) (net.Conn, error)

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.

func Run

func Run(ctx context.Context, b Backend, name string, argv []string, input []byte) (stdout, stderr []byte, code int, err error)

Run execs argv with input as stdin and collects the output.

func ValidName

func ValidName(name string) error

ValidName reports whether name can be a sprite in container mode.

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.

func NewDocker

func NewDocker(cfg Config) (*Docker, error)

NewDocker connects to the Docker socket.

func (*Docker) Create

func (d *Docker) Create(ctx context.Context, name string) error

Create implements Backend.

func (*Docker) Delete

func (d *Docker) Delete(ctx context.Context, name string) error

Delete implements Backend.

func (*Docker) Exec

func (d *Docker) Exec(ctx context.Context, name string, argv []string, stdin bool) (Process, error)

Exec implements Backend: create an exec, then start it on a hijacked connection that carries Docker's multiplexed stdout/stderr frames.

func (*Docker) Kind

func (d *Docker) Kind() string

Kind implements Backend.

func (*Docker) List

func (d *Docker) List(ctx context.Context) ([]string, error)

List implements Backend.

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) Kind

func (k *Kubernetes) Kind() string

Kind implements Backend.

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.

Jump to

Keyboard shortcuts

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