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
- Variables
- func ConfigureGuest(ctx context.Context, c *agent.Client, id, name string, fresh, restore bool, ...) error
- func FreezeGuest(ctx context.Context, c *agent.Client, freeze bool) error
- func GuestReady(dir string) error
- func ImageRootfs(ctx context.Context, base string, s Spec) (string, error)
- func OpenConsole(ctx context.Context, path string, follow bool) (io.ReadCloser, error)
- func PrepareWarm(ctx context.Context, d Driver, dir, configuration string, ...) error
- func RotateConsole(path string) error
- func WarmSpec(s Spec) bool
- type Driver
- type GuestNetwork
- type Sandbox
- type Spec
- type State
Constants ¶
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.
const ConsoleMax = 1 << 20
ConsoleMax is the size at which RotateConsole rotates a console log.
const WarmID = "base"
WarmID is private to the separate warm-cache driver, never the user's store.
Variables ¶
var ErrNotSupported = errors.New("not supported by this backend")
ErrNotSupported is returned for operations a backend does not implement.
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 ¶
FreezeGuest quiesces the private base before saving it, or thaws a clone immediately after restore, before any disk writes or filesystem resizing.
func GuestReady ¶
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 ¶
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 ¶
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 ¶
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.
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 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 ¶
WithDefaults fills unspecified limits. MemoryMB is in MiB and DiskGB in GiB. Negative limits are invalid; zero means the common backend default.
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. |