vmruntime

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package vmruntime holds host-side state for the managed VM.

Index

Constants

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

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

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

View Source
const SchemaVersion = 1

SchemaVersion is bumped when the file layout changes incompatibly.

Variables

View Source
var ErrNotFound = errors.New("vm settings file not found")

ErrNotFound means no settings file exists yet.

Functions

func BootTimeout

func BootTimeout(env Lookup) (time.Duration, error)

BootTimeout reads APP_VM_BOOT_TIMEOUT as a Go duration.

func DashboardURL

func DashboardURL(port int) string

DashboardURL is the URL users and the desktop shell open for a dashboard port.

func DefaultPath

func DefaultPath() (string, error)

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 IntEnv

func IntEnv(env Lookup, name string, def int) (int, error)

IntEnv returns the integer in name, or def when unset or empty.

func Limits

func Limits(env Lookup, hostMemMiB, hostCPUs int, homeDir, dataDir string) (lima.Limits, error)

Limits derives lima limits from the host and APP_VM_MEMORY_* env.

func ReadToken

func ReadToken(ctx context.Context, r Runner) (string, error)

ReadToken returns the guest desktop token. It is held in memory only and never logged.

func Save

func Save(path string, s Settings) error

Save writes s atomically with mode 0600: temp file, fsync, rename.

func SocketPathMax

func SocketPathMax(env Lookup) (int, error)

SocketPathMax reads the unix socket path limit used to choose the Lima home.

func TokenExists

func TokenExists(ctx context.Context, r Runner) bool

TokenExists reports whether the guest token file is present.

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 Lookup

type Lookup func(string) (string, bool)

Lookup reads one env value, like os.LookupEnv.

type Runner

type Runner interface {
	Run(ctx context.Context, args ...string) ([]byte, error)
}

Runner is the part of limactl access ReadToken needs.

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 Load

func Load(path string) (Settings, error)

Load reads and checks the schema version of the file at path.

func SeedFromEnv

func SeedFromEnv(env Lookup) (Settings, error)

SeedFromEnv builds first-init settings from env over the ADR defaults. Ports stay 0 when unset: the caller picks free ones.

func (Settings) Pending

func (s Settings) Pending() []string

Pending lists settings whose stored value differs from the running one.

func (Settings) ToLima

func (s Settings) ToLima() lima.Settings

ToLima converts to template settings. Sidecar is supplied by the caller.

func (Settings) UpgradeTimeout

func (s Settings) UpgradeTimeout(env Lookup) (time.Duration, error)

UpgradeTimeout is the stored health gate, else env, else the default.

func (Settings) Validate

func (s Settings) Validate(l lima.Limits) error

Validate checks the settings through the template validator.

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.

Jump to

Keyboard shortcuts

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