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
- Variables
- func ConfigPath(dir string) string
- func Logout(dir string, store CredStore) error
- func Passed(cs []Check) bool
- func SaveConfig(dir string, c Config) error
- func VMState(ctx context.Context, r Runner) (string, error)
- type Check
- type Config
- type CredStore
- type DoctorEnv
- type FileStore
- type Host
- type JoinInput
- type Limits
- type Lookup
- type Runner
- type Status
Constants ¶
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 ¶
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 SaveConfig ¶
SaveConfig writes the config with mode 0600 in a 0700 directory.
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.
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 LoadConfig ¶
LoadConfig reads the config, or ErrNotJoined.
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.
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 ¶
Start boots the VM and the agent. agentBin is a linux agent build, copied in when given.
type Limits ¶
Limits are the resource and power settings of a builder.
func LookupLimits ¶
LookupLimits seeds limits from env; flags override the result.
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.