Documentation
¶
Overview ¶
Package labs is the registry of the labs on this machine: one entry per cluster name, pointing at the lab directory that holds its agentlab.yaml, certs/ and state/. `configure` and `up` write it; every command that runs against a lab resolves the lab through it (Resolve), so a person no longer has to `cd` into the lab first. An entry is a lab's Home under the freedesktop folders, or a lab directory from before them, which the first command that enters it moves there (Settle).
Index ¶
- Variables
- func Check(name, dir string) error
- func ConfigFile(name string) (string, error)
- func FreeName(name, dir string) (string, error)
- func Home(name string) (string, error)
- func RecordedDomains(dir string) (map[string]string, error)
- func RecordedPorts(dir string) (map[string]string, error)
- func Register(name, dir string) error
- func Removable(name, dir string) error
- func Remove(name string) error
- func Settle(name, dir string) (string, error)
- type ConfigConflictError
- type CrossDeviceError
- type Lab
- type Mode
- type OutsideHomeError
- type Picker
- type TakenError
Constants ¶
This section is empty.
Variables ¶
var Dir = xdg.ConfigHome
Dir is the registry's directory: agentlab's configuration folder ($XDG_CONFIG_HOME/agentlab, ~/.config/agentlab by default; ~/Library/Application Support/agentlab on macOS). A variable so tests can point it at a temporary directory.
Functions ¶
func Check ¶
Check refuses a name registered to a different, still existing lab directory; it writes nothing. `configure` and the first run call it before they save an agentlab.yaml, so a refused name leaves no file behind.
func ConfigFile ¶ added in v0.120.0
ConfigFile is the lab's agentlab.yaml under agentlab's configuration folder ($XDG_CONFIG_HOME/agentlab/labs/<name>/agentlab.yaml).
func FreeName ¶ added in v0.111.0
FreeName returns name when Check would accept it for dir, else the first of name-2, name-3, … that no other lab directory holds: the default name of a new lab on a machine where name is taken. It writes nothing.
func Home ¶ added in v0.120.0
Home is the lab's directory under agentlab's state folder ($XDG_STATE_HOME/agentlab/labs/<name>): its certs/ (the lab CA), state/ (kubeconfigs, rendered manifests, the kind node's mounted files) and the rest of what the lab writes. Every command runs in it, so the lab's relative paths hold. Its agentlab.yaml is a link to ConfigFile — or, on macOS, where the state folder is the configuration folder, ConfigFile itself.
func RecordedDomains ¶ added in v0.119.0
RecordedDomains returns the platform domain every other registered lab records, mapped to the first lab by name that records it: two labs on one domain serve the same hostnames, and a browser's state for one (cookies, an HSTS pin, the trusted CA) then applies to the other.
func RecordedPorts ¶ added in v0.111.0
RecordedPorts returns the host addresses (host:port) every other registered lab records in its agentlab.yaml — running or stopped — each mapped to that lab's name, so the lab in dir picks ports none of them can come up on. A lab whose agentlab.yaml does not parse is left out: it cannot come up either.
func Register ¶
Register records dir as the lab of that name, dropping any other name the directory was registered under (a changed clusterName) and the entries whose directory no longer holds a lab. A name registered to another existing lab directory is refused with a *TakenError.
func Removable ¶ added in v0.140.0
Removable refuses (*OutsideHomeError) to remove the lab of that name when dir, where it is entered, or the directory the registry names for it is not its Home.
func Remove ¶ added in v0.140.0
Remove deletes the lab of that name for good: its Home with certs/ and state/, its configuration folder and its registry entry. A lab Removable refuses stays as it is.
func Settle ¶ added in v0.120.0
Settle puts the lab of that name into the freedesktop folders and returns the directory the command runs in, Home(name). dir is where the lab lives now: Home itself (nothing to do but keep the link), a lab directory from before the folders (a checkout, a dedicated directory) or a directory with no lab yet, for a new one.
A lab from elsewhere is moved, not copied: its agentlab.yaml to ConfigFile, certs/, state/ and the other lab files into Home, each by a rename, so nothing is lost and no file is written twice. Each moved file leaves a link at its old path: the kind node of a running lab mounts certs/ and state/node by their old absolute paths and resolves them again on a restart, and an older agentlab run in the old directory finds its lab there. A move across file systems is refused before anything moves (*CrossDeviceError); a failure halfway moves back what had moved. An agentlab.yaml that is a file of its own in Home moves to ConfigFile, a link in its place (adoptConfig) — unless it is ConfigFile, as on macOS, where Home is ConfigFile's folder: then it is the lab's configuration and stays a file (#1106).
Types ¶
type ConfigConflictError ¶ added in v0.120.0
type ConfigConflictError struct {
Name, Home, Config, Newer string
}
ConfigConflictError is Settle's refusal to choose between two different agentlab.yaml files of one lab: a file of its own in the lab's Home and the one in the configuration folder. Both stay as they are.
func (*ConfigConflictError) Error ¶ added in v0.120.0
func (e *ConfigConflictError) Error() string
type CrossDeviceError ¶ added in v0.120.0
type CrossDeviceError struct {
Dir, Home string
}
CrossDeviceError is Settle's refusal to move a lab between file systems: a rename there is a copy, which a running lab's kind node mounts would not follow. Nothing was moved; the lab stays where it is.
func (*CrossDeviceError) Error ¶ added in v0.120.0
func (e *CrossDeviceError) Error() string
type Lab ¶
Lab is one registered lab: its cluster name (agentlab.yaml's clusterName, the lab's name everywhere) and its absolute directory.
func List ¶
List returns the registered labs sorted by name. Entries whose directory or agentlab.yaml is gone are left out — neither offered nor listed — but kept in the file: a read never writes, so a lab whose agentlab.yaml is away for a moment (moved aside, being rewritten) is back once the file is. Register drops the stale entries when it writes.
func Resolve ¶
Resolve decides which lab directory a command runs against, in one order:
- --lab <name> (flag), refused naming the registered labs when unknown;
- the agentlab.yaml in the current directory: the lab its clusterName names, registered elsewhere (a copy of that lab's file), or else this directory — always this directory under Create and Here;
- unless Create: on a terminal (pick non-nil) the person's choice among the registered labs, off one a refusal naming them and --lab.
No lab is ever the default: a command runs against the lab the flag, the directory or the person names, or not at all. dir is "" for the current directory — also when nothing is registered, so the caller's missing-agentlab.yaml path (the first run, or its refusal) stays what it is.
type Mode ¶ added in v0.112.0
type Mode int
Mode is how a command treats the current directory when it resolves its lab.
const ( // Enter is every command that runs against an existing lab: an // agentlab.yaml here enters the lab its clusterName names, wherever that // lab is registered. Enter Mode = iota // Create is for the commands that make a lab where they run // (`configure`, `up`): in the current directory they stay there instead // of reaching for another lab, with or without an agentlab.yaml. Create // Here is for the commands that only write the lab's files from its // agentlab.yaml (`render`): an agentlab.yaml here is this directory's // lab, even a copy of a registered lab's, so the registered lab's certs/ // and state/ are never rewritten from a file outside its directory; // without one they resolve as Enter. Here )
type OutsideHomeError ¶ added in v0.140.0
type OutsideHomeError struct {
Name, Dir string
}
OutsideHomeError is the refusal to remove a lab that lives in a directory other than its Home (one Settle left where it was): that directory may hold more than the lab. Nothing was changed.
func (*OutsideHomeError) Error ¶ added in v0.140.0
func (e *OutsideHomeError) Error() string
type TakenError ¶
type TakenError struct {
Name string
Dir string // the directory asking for the name
Other string // the directory the name is registered to
}
TakenError refuses a second lab of a registered name: the two would collide on the kind cluster and its ports.
func (*TakenError) Error ¶
func (e *TakenError) Error() string