backend

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 14 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 backend defines the interface every sandbox backend implements.

Planned backends: Firecracker (Linux with KVM), Docker (Linux fallback) and Apple's Virtualization framework (macOS on Apple silicon).

Index

Constants

View Source
const (
	DefaultCPUs     = 2
	DefaultMemoryMB = 2048
	DefaultDiskGB   = 10
)

Defaults are shared by backend callers and the daemon/CLI. Memory is in MiB and disk capacity in GiB.

View Source
const ConsoleMax = 1 << 20

ConsoleMax is the size at which RotateConsole rotates a console log.

View Source
const WarmID = "base"

WarmID is private to the separate warm-cache driver, never the user's store.

Variables

View Source
var ErrNotSupported = errors.New("not supported by this backend")

ErrNotSupported is returned for operations a backend does not implement.

View Source
var ErrUncleanStop = errors.New("sandbox was not stopped cleanly")

ErrUncleanStop is wrapped by Stop's error when the sandbox is stopped but the guest's shutdown did not complete, so its disk may be inconsistent and may need a filesystem check.

Functions

func ConfigureGuest

func ConfigureGuest(ctx context.Context, c *agent.Client, id, name string, fresh, restore bool, network GuestNetwork) error

ConfigureGuest runs before exposing a new VM. Fresh restores must replace cloned identity and reseed the kernel RNG before any user code runs.

func FreezeGuest

func FreezeGuest(ctx context.Context, c *agent.Client, freeze bool) error

FreezeGuest quiesces the private base before saving it, or thaws a clone immediately after restore, before any disk writes or filesystem resizing.

func GuestReady

func GuestReady(dir string) error

GuestReady keeps concurrent API requests out of a fresh VM until its cloned identity and RNG have been replaced. Host-side setup bypasses Dial.

func ImageRootfs

func ImageRootfs(ctx context.Context, base string, s Spec) (string, error)

ImageRootfs selects a VM image, fetching the pinned desktop disk only when requested. Snapshot disks already contain their image, so From takes precedence.

func OpenConsole

func OpenConsole(ctx context.Context, path string, follow bool) (io.ReadCloser, error)

OpenConsole reads the current console log, optionally waiting for new bytes. Follow reopens renamed logs and rewinds copy-truncated logs.

func PrepareWarm

func PrepareWarm(ctx context.Context, d Driver, dir, configuration string, quiesce func(context.Context) error, artifacts ...string) error

PrepareWarm boots and pauses a private base VM, or reuses its complete cache. The separate driver keeps it out of sandbox listings and user reservations. Hash the published artifacts, not the mutable disk, to invalidate on upgrades.

func RotateConsole

func RotateConsole(path string) error

RotateConsole copies path to path.1, replacing it, and empties path once path is larger than ConsoleMax. The VM writes path with O_APPEND, so it carries on at the new end.

func WarmSpec

func WarmSpec(s Spec) bool

WarmSpec is the only configuration cached. Other sizes and named disk snapshots cold-boot: saved memory must exactly match the disk and VM size.

Types

type Driver

type Driver interface {
	Name() string
	Create(ctx context.Context, id string, spec Spec) (Sandbox, error)
	Start(ctx context.Context, id string) error
	Pause(ctx context.Context, id string) error
	Resume(ctx context.Context, id string) error
	Stop(ctx context.Context, id string) error
	Remove(ctx context.Context, id string) error
	List(ctx context.Context) ([]Sandbox, error)
	// Snapshot copies the disk of a stopped sandbox to path, a new file in
	// the state directory, for Spec.From. The sandbox stays usable.
	Snapshot(ctx context.Context, id, path string) error
}

Driver is implemented by each backend. The caller picks the ID, so the store and the backend name a sandbox the same way; it must be usable as a file name.

type GuestNetwork

type GuestNetwork struct {
	Address, Mask, Gateway, Resolvers string
}

GuestNetwork replaces the network identity captured in a warm snapshot. Empty fields leave the kernel's cold-boot configuration alone.

type Sandbox

type Sandbox struct {
	ID    string
	Name  string
	State State
}

Sandbox is a sandbox as a backend reports it.

type Spec

type Spec struct {
	Name     string
	Image    string
	CPUs     int
	MemoryMB int
	DiskGB   int
	// From, if set, is a snapshot that Snapshot wrote, to copy the disk
	// from instead of the base image. DiskGB must be at least its size.
	From string `json:"-"`
}

Spec describes the sandbox to create.

func (Spec) WithDefaults

func (s Spec) WithDefaults() (Spec, error)

WithDefaults fills unspecified limits. MemoryMB is in MiB and DiskGB in GiB. Negative limits are invalid; zero means the common backend default.

type State

type State string

State is a sandbox's lifecycle state.

const (
	StateRunning State = "running"
	StatePaused  State = "paused"
	StateStopped State = "stopped"
)

Directories

Path Synopsis
Package docker is the fallback backend for Linux hosts without KVM.
Package docker is the fallback backend for Linux hosts without KVM.
Package firecracker is the Firecracker backend for Linux with KVM.
Package firecracker is the Firecracker backend for Linux with KVM.
Package vz is the backend for macOS on Apple silicon.
Package vz is the backend for macOS on Apple silicon.
Package warmtest shares the real-hypervisor warm-clone checks.
Package warmtest shares the real-hypervisor warm-clone checks.

Jump to

Keyboard shortcuts

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