Documentation
¶
Overview ¶
Package vmruntime holds host-side state for the managed VM.
Index ¶
- Constants
- Variables
- 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 Limits(env Lookup, hostMemMiB, hostCPUs int, homeDir, dataDir string) (lima.Limits, error)
- func ReadToken(ctx context.Context, r Runner) (string, error)
- func Save(path string, s Settings) error
- func SocketPathMax(env Lookup) (int, error)
- func TokenExists(ctx context.Context, r Runner) bool
- type Applied
- type Lookup
- type Runner
- type Settings
- type UpgradeBackup
Constants ¶
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" 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 )
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.
Variables ¶
var ErrNotFound = errors.New("vm settings file not found")
ErrNotFound means no settings file exists yet.
Functions ¶
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 ReadToken ¶
ReadToken returns the guest desktop token. It is held in memory only and never logged.
func SocketPathMax ¶
SocketPathMax reads the unix socket path limit used to choose the Lima home.
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"`
}
Applied is what the running instance was last started with, so status can show settings that wait for a restart.
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"`
// UpgradeHealth is a Go duration, seeded from env at init; the stored value wins.
UpgradeHealth string `json:"upgrade_health_timeout,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) UpgradeTimeout ¶
UpgradeTimeout is the stored health gate, else env, else the default.
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.
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. |