Documentation
¶
Overview ¶
Package vmruntime holds host-side state for the managed VM.
Index ¶
- Constants
- Variables
- func BeginOperation(path, name string) (func(), error)
- func BootTimeout(env Lookup) (time.Duration, error)
- func DashboardURL(port int) string
- func DefaultPath() (string, error)
- func Exchange(ctx context.Context, client *http.Client, port int, token string) (*http.Cookie, string, error)
- func IntEnv(env Lookup, name string, def int) (int, error)
- func LifecyclePath(dataDir string) string
- func Limits(env Lookup, hostMemMiB, hostCPUs int, homeDir, dataDir string) (lima.Limits, error)
- func LockFile(f *os.File) error
- func LockPath(path string) string
- func ParseOnOff(v string) (bool, error)
- func ReadToken(ctx context.Context, r Runner) (string, error)
- func Save(path string, s Settings) error
- func ShareIdentity(path string) (string, error)
- func SocketPathMax(env Lookup) (int, error)
- func TokenExists(ctx context.Context, r Runner) bool
- func TryLockFile(f *os.File) bool
- func Update(path string, apply func(*Settings) error) error
- func Upsert(path string, fresh Settings, apply func(*Settings)) error
- type Applied
- type BootWindow
- type BusyError
- type Lookup
- type Operation
- type Recheck
- type Runner
- type Settings
- func (s *Settings) AdoptShareIdentities(l lima.Limits) error
- func (s Settings) ListErrorLimit(env Lookup) int
- func (s Settings) NeedsShareIdentity() bool
- func (s Settings) Pending() []string
- func (s Settings) PinShares() (Settings, error)
- func (s Settings) RecheckInterval() int
- func (s Settings) RecreateAdvised(env Lookup) bool
- func (s Settings) SetupIncomplete() bool
- func (s Settings) ToLima() lima.Settings
- func (s Settings) UpgradeTimeout(env Lookup) (time.Duration, error)
- func (s Settings) Validate(l lima.Limits) error
- func (s Settings) Window(env Lookup) (BootWindow, error)
- type Setup
- type Share
- type UpgradeBackup
Constants ¶
const ( EnvFirstBootTimeout = "APP_VM_FIRST_BOOT_TIMEOUT" EnvFirstBootMax = "APP_VM_FIRST_BOOT_MAX" EnvFirstBootStall = "APP_VM_FIRST_BOOT_STALL" EnvSetupAttempts = "APP_VM_SETUP_ATTEMPTS" )
Env names for the first boot window. They seed the settings file at init.
const ( DefaultFirstBootTimeout = 20 * time.Minute DefaultFirstBootMax = 45 * time.Minute DefaultFirstBootStall = 5 * time.Minute // DefaultSetupAttempts is how many failed setup boots pass before recreating is advised. DefaultSetupAttempts = 3 )
A first boot downloads and installs packages, so it gets far longer than a normal start.
const ( EnvExperimental = "APP_VM_EXPERIMENTAL" EnvMemoryMiB = "APP_VM_MEMORY_MIB" EnvCPUs = "APP_VM_CPUS" EnvDiskGiB = "APP_VM_DISK_GIB" EnvMemoryMaxPct = "APP_VM_MEMORY_MAX_PERCENT" EnvMemoryMinMiB = "APP_VM_MEMORY_MIN_MIB" EnvBootTimeout = "APP_VM_BOOT_TIMEOUT" EnvDashboardPort = "APP_VM_DASHBOARD_PORT" EnvIngressPort = "APP_VM_INGRESS_PORT" EnvUpgradeHealth = "APP_VM_UPGRADE_HEALTH_TIMEOUT" EnvSocketPathMax = "APP_VM_SOCKET_PATH_MAX" EnvDockerSocket = "APP_VM_DOCKER_SOCKET" EnvRecheckSec = "APP_VM_ISOLATION_RECHECK_SEC" EnvWatchListErrors = "APP_VM_WATCH_LIST_ERRORS" DefaultBootTimeout = 180 * time.Second // DefaultUpgradeHealth is how long vm upgrade waits for the new control plane before rolling back. DefaultUpgradeHealth = 5 * time.Minute // DefaultSocketPathMax is the unix socket path limit on macOS (sun_path, with its NUL). DefaultSocketPathMax = 104 // DefaultWatchListErrors is how many failed VM listings in a row the watcher tolerates. DefaultWatchListErrors = 3 )
Env names. Env only seeds the file at init; the stored value wins afterwards.
const ( Instance = "levelrail" TokenPath = "/var/lib/levelrail/data/desktop-token" //nolint:gosec // a guest file path, not a credential // ExchangePath and SessionCookie mirror internal/desktopmode. ExchangePath = "/api/desktop/exchange" SessionCookie = "session_token" )
Guest names the host side reaches over limactl.
const DashboardHost = "levelrail.localhost"
DashboardHost is the only host name desktop mode serves on, so cookies stay host-only and never leak across other localhost ports.
const SchemaVersion = 1
SchemaVersion is bumped when the file layout changes incompatibly.
const StageRepairFailed = "failed:repair"
StageRepairFailed is reported by the guest when its package database could not be repaired.
Variables ¶
var ErrNotFound = errors.New("vm settings file not found")
ErrNotFound means no settings file exists yet.
Functions ¶
func BeginOperation ¶
BeginOperation takes the lifecycle lock for name, or returns a *BusyError without waiting for the holder. The returned func releases it; a dead process releases it by itself.
func BootTimeout ¶
BootTimeout reads APP_VM_BOOT_TIMEOUT as a Go duration.
func DashboardURL ¶
DashboardURL is the URL users and the desktop shell open for a dashboard port.
func DefaultPath ¶
DefaultPath is the settings file under the user config dir.
func Exchange ¶
func Exchange(ctx context.Context, client *http.Client, port int, token string) (*http.Cookie, string, error)
Exchange trades the token for a dashboard session on the loopback port. The Host header is the desktop name, which is all the control plane serves.
func LifecyclePath ¶
LifecyclePath is the lock file that lets one lifecycle command at a time touch the VM.
func ReadToken ¶
ReadToken returns the guest desktop token. It is held in memory only and never logged.
func ShareIdentity ¶
ShareIdentity names the folder object at path, so a different folder put there later is told apart.
func SocketPathMax ¶
SocketPathMax reads the unix socket path limit used to choose the Lima home.
func TokenExists ¶
TokenExists reports whether the guest token file is present.
func TryLockFile ¶
TryLockFile takes the lock only if nobody holds it.
Types ¶
type Applied ¶
type Applied struct {
MemoryMiB int `json:"memory_mib"`
CPUs int `json:"cpus"`
DiskGiB int `json:"disk_gib"`
DashboardPort int `json:"dashboard_port"`
IngressPort int `json:"ingress_port"`
// Shares are the folders mounted at that start.
DockerSocket bool `json:"docker_socket,omitempty"`
RecheckSec int `json:"isolation_recheck_seconds,omitempty"`
}
Applied is what the running instance was last started with, so status can show settings that wait for a restart.
type BootWindow ¶
type BootWindow struct {
// Base is the normal limit. Max is the hard ceiling, reachable only while progress is seen.
Base, Max time.Duration
// Stall is how recent progress must be to keep waiting past Base. Zero never extends.
Stall time.Duration
}
BootWindow bounds how long a start may run before the guest has to have passed its isolation check.
type BusyError ¶
type BusyError struct{ Op Operation }
BusyError means another lifecycle command is still running.
type Operation ¶
type Operation struct {
Name string `json:"name"`
PID int `json:"pid"`
Since string `json:"since"`
}
Operation is the lifecycle command that holds the VM.
func CurrentOperation ¶
CurrentOperation reports the lifecycle command in progress, if a live process holds the lock.
type Recheck ¶
type Recheck struct {
At string `json:"at"`
Result string `json:"result"` // pass or fail
Detail string `json:"detail,omitempty"`
}
Recheck is the last isolation check the host ran while the Docker socket was on.
type Settings ¶
type Settings struct {
Version int `json:"version"`
MemoryMiB int `json:"memory_mib"`
CPUs int `json:"cpus"`
DiskGiB int `json:"disk_gib"`
DashboardPort int `json:"dashboard_port"`
IngressPort int `json:"ingress_port"`
Applied *Applied `json:"applied,omitempty"`
// Shares is empty unless the user opts in with `vm share add`.
// DockerSocket gives the Mac's docker CLI the guest engine. Off unless the user opts in.
DockerSocket bool `json:"docker_socket,omitempty"`
RecheckSec int `json:"isolation_recheck_seconds,omitempty"`
LastRecheck *Recheck `json:"last_recheck,omitempty"`
// WatchListErrors is seeded from env at init; the stored value wins.
WatchListErrors int `json:"watch_list_errors,omitempty"`
// StartingUntil marks a start in progress, when a recheck would see a half provisioned guest.
StartingUntil string `json:"starting_until,omitempty"`
// UpgradeHealth is a Go duration, seeded from env at init; the stored value wins.
UpgradeHealth string `json:"upgrade_health_timeout,omitempty"`
// First boot limits and the setup attempt count, seeded from env at init; the stored values win.
FirstBootTimeout string `json:"first_boot_timeout,omitempty"`
FirstBootMax string `json:"first_boot_max,omitempty"`
FirstBootStall string `json:"first_boot_stall,omitempty"`
SetupAttempts int `json:"setup_attempts,omitempty"`
// Setup is set while setup is unfinished.
Setup *Setup `json:"setup,omitempty"`
UpgradeBackup *UpgradeBackup `json:"upgrade_backup,omitempty"`
}
Settings is the host settings file. Ports are host loopback ports.
func SeedFromEnv ¶
SeedFromEnv builds first-init settings from env over the ADR defaults. Ports stay 0 when unset: the caller picks free ones.
func (*Settings) AdoptShareIdentities ¶
AdoptShareIdentities records the identity of such shares once they pass every share check. From then on a different folder at the same path is refused.
func (Settings) ListErrorLimit ¶
ListErrorLimit is the stored count, else env, else the default; never below one.
func (Settings) NeedsShareIdentity ¶
NeedsShareIdentity reports shares stored before identities were recorded.
func (Settings) PinShares ¶
PinShares re-resolves every share right before use and returns settings that carry the resolved paths. It fails when a path no longer leads to the folder that was shared.
func (Settings) RecheckInterval ¶
RecheckInterval is the stored seconds between isolation rechecks, or the default.
func (Settings) RecreateAdvised ¶
RecreateAdvised reports that resuming has failed often enough, or the guest cannot be repaired.
func (Settings) SetupIncomplete ¶
SetupIncomplete reports a guest that never finished setup, so it holds no apps or data.
func (Settings) UpgradeTimeout ¶
UpgradeTimeout is the stored health gate, else env, else the default.
type Setup ¶
type Setup struct {
// ControlPlaneBin and ControlPlaneSHA let a later `vm start` finish an interrupted init.
ControlPlaneBin string `json:"control_plane_bin,omitempty"`
ControlPlaneSHA string `json:"control_plane_sha256,omitempty"`
Failures int `json:"failures,omitempty"`
// Stage is the last provisioning step the guest reported.
Stage string `json:"stage,omitempty"`
LastError string `json:"last_error,omitempty"`
}
Setup is present until a start has provisioned the guest and installed the control plane.
type Share ¶
type Share struct {
Identity string `json:"identity,omitempty"`
}
Share is one opted-in host folder, always mounted read-only.
type UpgradeBackup ¶
type UpgradeBackup struct {
Path string `json:"path"`
At string `json:"at"`
Result string `json:"result"`
}
UpgradeBackup records the last guest data backup taken by vm upgrade.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package guest holds the files and helpers that run inside the managed VM: the egress firewall baseline, the isolation self-check and the provisioning script.
|
Package guest holds the files and helpers that run inside the managed VM: the egress firewall baseline, the isolation self-check and the provisioning script. |
|
Package lima renders and validates the Lima template for the managed VM.
|
Package lima renders and validates the Lima template for the managed VM. |
|
Package limadist downloads and installs the pinned Lima release the managed VM runs on.
|
Package limadist downloads and installs the pinned Lima release the managed VM runs on. |