buildernode

package
v1.5.9 Latest Latest
Warning

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

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

Documentation

Overview

Package buildernode is the host side of a laptop builder: join config, credential storage, doctor checks and the lifecycle of the managed VM that runs the agent.

Index

Constants

View Source
const (
	EnvMaxCPU        = "APP_BUILDER_MAX_CPU"
	EnvMaxMemMiB     = "APP_BUILDER_MAX_MEM_MIB"
	EnvIdleStop      = "APP_BUILDER_IDLE_STOP"
	EnvPauseBattery  = "APP_BUILDER_PAUSE_ON_BATTERY"
	EnvMinRAMMiB     = "APP_BUILDER_MIN_RAM_MIB"
	EnvMinDiskGiB    = "APP_BUILDER_MIN_DISK_GIB"
	EnvMaxClockSkew  = "APP_BUILDER_MAX_CLOCK_SKEW"
	EnvPollInterval  = "APP_BUILDER_POLL_INTERVAL"
	EnvIdleLoad      = "APP_BUILDER_IDLE_LOAD"
	EnvAgentPort     = "APP_BUILDER_AGENT_PORT"
	EnvProbeTimeout  = "APP_BUILDER_PROBE_TIMEOUT"
	DefaultMaxCPU    = 4
	DefaultMaxMemMiB = 6144
	DefaultMinRAMMiB = 8192
	DefaultMinDisk   = 40
	DefaultAgentPort = 8081
	DefaultSkew      = 30 * time.Second
	DefaultPoll      = 30 * time.Second
	DefaultProbe     = 10 * time.Second
	DefaultIdleLoad  = 0.2
	// Instance is a separate Lima instance so a builder never shares a disk with a control plane VM.
	Instance = "levelrail-builder"
	// ConfigVersion is bumped when the file layout changes incompatibly.
	ConfigVersion = 1
)

Env names. Env only seeds flag defaults; flags and the stored config win.

Variables

View Source
var ErrNotJoined = errors.New("this machine has not joined a control plane; run `levelrail builder join` first")

ErrNotJoined means no config exists yet.

Functions

func ConfigPath

func ConfigPath(dir string) string

ConfigPath is the config file inside dir.

func Logout

func Logout(dir string, store CredStore) error

Logout stops using this machine as a builder: it forgets the token and the config.

func Passed

func Passed(cs []Check) bool

Passed reports whether every check is OK.

func SaveConfig

func SaveConfig(dir string, c Config) error

SaveConfig writes the config with mode 0600 in a 0700 directory.

func VMState

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

VMState returns the Lima status of the builder instance: "Running", "Stopped" or "" when absent.

Types

type Check

type Check struct {
	Name   string `json:"name"`
	OK     bool   `json:"ok"`
	Detail string `json:"detail"`
	// Fix is one actionable line, set only on a failing check.
	Fix string `json:"fix,omitempty"`
}

Check is one doctor result.

func Doctor

func Doctor(ctx context.Context, e DoctorEnv) ([]Check, error)

Doctor runs every check and never stops at the first failure.

type Config

type Config struct {
	Version        int    `json:"version"`
	Server         string `json:"server"`
	AgentAddr      string `json:"agent_addr"`
	NodeName       string `json:"node_name"`
	CAFingerprint  string `json:"ca_fingerprint,omitempty"`
	MaxCPU         int    `json:"max_cpu"`
	MaxMemMiB      int    `json:"max_mem_mib"`
	IdleStop       string `json:"idle_stop,omitempty"`
	PauseOnBattery bool   `json:"pause_on_battery"`
}

Config is the stored builder config. It never holds the join token.

func Join

func Join(dir string, store CredStore, in JoinInput, env Lookup) (Config, error)

Join validates the input, stores the token and writes the config.

func LoadConfig

func LoadConfig(dir string) (Config, error)

LoadConfig reads the config, or ErrNotJoined.

type CredStore

type CredStore interface {
	Save(token string) error
	Load() (string, error)
	Delete() error
}

CredStore holds the one-time join token. The file store is the portable default.

type DoctorEnv

type DoctorEnv struct {
	Arch         string
	HostMemMiB   int
	DiskFreeGiB  int
	LimaPath     func() (string, error)
	Runner       Runner
	ServerTime   func(ctx context.Context, server string) (time.Time, error)
	Now          func() time.Time
	Env          Lookup
	ConfigServer string
}

DoctorEnv is everything doctor reads from the host, injected so tests run offline.

type FileStore

type FileStore struct{ Path string }

FileStore keeps the token in a 0600 file next to the config.

func NewFileStore

func NewFileStore(dir string) FileStore

NewFileStore returns the store for dir.

func (FileStore) Delete

func (s FileStore) Delete() error

Delete removes the token; a missing file is fine.

func (FileStore) Load

func (s FileStore) Load() (string, error)

Load returns the token, or an empty string when none is stored.

func (FileStore) Save

func (s FileStore) Save(token string) error

Save writes the token.

type Host

type Host struct {
	Runner      Runner
	Store       CredStore
	InstanceDir string
	Render      func(cpus, memMiB int) ([]byte, error)
	OnBattery   func(ctx context.Context) (bool, error)
	Sleep       func(time.Duration)
	Env         Lookup
	Out         io.Writer
}

Host is the VM side of a builder. Every outside effect is injected.

func (*Host) Start

func (h *Host) Start(ctx context.Context, c Config, agentBin string) error

Start boots the VM and the agent. agentBin is a linux agent build, copied in when given.

func (*Host) Status

func (h *Host) Status(ctx context.Context, dir string) (Status, error)

Status reads config, VM and agent state.

func (*Host) Stop

func (h *Host) Stop(ctx context.Context) error

Stop stops the agent, then the VM. A VM that does not exist is already stopped.

func (*Host) Supervise

func (h *Host) Supervise(ctx context.Context, c Config) error

Supervise enforces pause-on-battery and the idle auto-stop until ctx ends or it stops the VM.

type JoinInput

type JoinInput struct {
	Server, Token, NodeName, AgentAddr, CAFingerprint string
	Limits                                            Limits
}

JoinInput is what `builder join` receives.

type Limits

type Limits struct {
	MaxCPU         int
	MaxMemMiB      int
	IdleStop       time.Duration
	PauseOnBattery bool
}

Limits are the resource and power settings of a builder.

func LookupLimits

func LookupLimits(env Lookup) (Limits, error)

LookupLimits seeds limits from env; flags override the result.

type Lookup

type Lookup func(string) (string, bool)

Lookup reads one environment value.

type Runner

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

Runner is the only door to limactl, so tests never boot a VM.

type Status

type Status struct {
	Joined  bool   `json:"joined"`
	Server  string `json:"server,omitempty"`
	Node    string `json:"node,omitempty"`
	VM      string `json:"vm"`
	Agent   string `json:"agent"`
	MaxCPU  int    `json:"max_cpu,omitempty"`
	MaxMem  int    `json:"max_mem_mib,omitempty"`
	Battery bool   `json:"pause_on_battery"`
	IdleMin string `json:"idle_stop,omitempty"`
}

Status is the host view of the builder.

Jump to

Keyboard shortcuts

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