local

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package local manages the local Agyn platform VM: downloading prebuilt images from the CDN, driving Lima, and handling the local CA.

Index

Constants

View Source
const (
	// DefaultInstanceName is the VM `agyn local` acts on when none is named.
	DefaultInstanceName = "agyn"

	// DefaultBaseURL serves the published platform VM images.
	DefaultBaseURL = "https://downloads.agyn.cloud/bundle-vm"

	// BaseURLEnv overrides the download endpoint.
	BaseURLEnv = "AGYN_LOCAL_BASE_URL"

	// BaseDomain is the wildcard domain routed to the VM ingress; it resolves
	// to 127.0.0.1 publicly.
	BaseDomain = "agyn.dev"

	// IngressNodePort is the guest NodePort the Istio ingress gateway listens
	// on inside the VM; the configured local port forwards to it.
	IngressNodePort = 32443
)
View Source
const (
	// BootstrapTokenPrefix marks a token this CLI minted for a local VM, so a
	// credential stored under the same profile by something else — a remote
	// cluster's API token, say — is never mistaken for one.
	BootstrapTokenPrefix = "agyn_local_"
)

Variables

View Source
var BootLogNames = []string{"ha.stderr.log", "serial.log"}

BootLogNames are the instance logs preserved when a boot fails, in the order they are worth reading: why the VM would not start, then how far the guest got if it did.

Functions

func Arch

func Arch() (string, error)

Arch maps the host architecture to the published image architecture.

func BaseURL

func BaseURL() string

BaseURL returns the CDN endpoint, honoring the environment override.

func CAPath

func CAPath() (string, error)

CAPath returns where the extracted CA is cached.

func CertsDir

func CertsDir() (string, error)

CertsDir returns the directory holding this VM's extracted CA. Each VM signs with its own CA, so they cannot share a file. The default VM keeps the original path, leaving existing installs where they are.

func CheckAPIPort

func CheckAPIPort(apiPort int) error

CheckAPIPort verifies the forwarded k3s API answers TLS on the host port. VMs created before the API forward existed need to be recreated to get it.

func ConsoleURL added in v0.17.0

func ConsoleURL(port int) string

ConsoleURL is where a finished start sends the user.

func CreateAndStart

func CreateAndStart(imageDir string, opts VMOptions, stdout, stderr io.Writer) error

CreateAndStart creates the instance from a downloaded image directory and boots it. The image's lima.yaml template is adjusted with the requested options before use.

func DecompressImage added in v0.17.0

func DecompressImage(version, arch string) (string, error)

DecompressImage expands the downloaded archive into the qcow2 disk Lima boots, and returns the image directory.

func Delete

func Delete(stdout, stderr io.Writer) error

Delete removes the instance and its disk state.

func Dir

func Dir() (string, error)

Dir returns ~/.agyn/local, the root for everything `agyn local` stores.

func DiskFileName

func DiskFileName(arch string) string

DiskFileName returns the qcow2 file name for an architecture.

func EnsureCA

func EnsureCA() (string, error)

EnsureCA extracts the CA from the running VM unless already cached.

func ExtractCA

func ExtractCA() error

ExtractCA reads the CA certificate from the running VM and caches it, overwriting any previous copy.

func FetchImage added in v0.17.0

func FetchImage(version, arch string, report func(detail string)) error

FetchImage downloads and verifies the compressed disk and the metadata beside it, reporting progress through report (which may be nil).

Download and decompression are separate calls because they are separate waits: one is minutes of network with a byte count to show, the other is minutes of CPU with nothing to show but that it is running.

func FetchKubeconfig

func FetchKubeconfig(apiPort int) (map[string]any, error)

FetchKubeconfig reads the k3s kubeconfig from the running VM and rewrites it to be usable from the host: server URL pointing at the forwarded API port and all entries named after the agyn-local context. k3s includes 127.0.0.1 in the API server certificate SANs, so TLS verification keeps working.

func GatewayURL

func GatewayURL(port int) string

GatewayURL returns the API endpoint the CLI talks to. It shares the ingress port with the browser endpoints; only the hostname differs.

func GenerateBootstrapToken

func GenerateBootstrapToken() (string, error)

GenerateBootstrapToken mints the Gateway bootstrap token for one install.

The host generates it rather than the image baking one in: a baked value ships on the CDN, is identical on every machine running that image version, and cannot be rotated. The encoding is URL-safe and unpadded so the value survives a shell argument, a YAML scalar and an Authorization header without quoting or escaping.

func HaveImage added in v0.17.0

func HaveImage(version, arch string) (string, bool, error)

HaveImage reports whether the decompressed disk for version/arch is already on this machine, and the directory it lives in either way.

func ImageDir

func ImageDir(version, arch string) (string, error)

ImageDir returns the directory holding a downloaded image version.

func InstallCA

func InstallCA() error

InstallCA adds the cached CA to the system trust store. Requires sudo.

func InstallCommand added in v0.17.0

func InstallCommand(tools []Tool) (string, bool)

InstallCommand is the command that would install these tools, and whether the detected installer can install all of them. A tool it does not package — lima outside Homebrew — leaves the caller to print that tool's own instruction.

func InstallTools added in v0.17.0

func InstallTools(tools []Tool, stdin io.Reader, stdout, stderr io.Writer) error

InstallTools runs the install command with the terminal attached, so brew reports its own progress and sudo can ask for a password.

func InstanceName

func InstanceName() string

InstanceName is the Lima instance this process acts on.

func IsBootstrapToken

func IsBootstrapToken(token string) bool

IsBootstrapToken reports whether a stored credential is one this CLI minted for a local VM.

func KubeContextName

func KubeContextName() string

KubeContextName() is the kubeconfig context/cluster/user name for this VM. Each VM is a separate cluster, so they cannot share a context name; the default VM keeps "agyn-local" so existing kubeconfigs keep working.

func LimaHome

func LimaHome() (string, error)

LimaHome returns the LIMA_HOME used for the managed instance so all VM state lives under ~/.agyn/local.

func MergeKubeconfig

func MergeKubeconfig(path string, fetched map[string]any) error

MergeKubeconfig upserts the agyn-local cluster/context/user into the kubeconfig at path (typically ~/.kube/config), preserving everything else. current-context is not changed.

func OrganizationID

func OrganizationID() (string, error)

OrganizationID reads the organization the release provisioned. The declaration records the assigned id on its own status, so this is read from the object the platform reconciles rather than from anything a script left behind -- and through limactl rather than over the network, like the CA.

func Reset

func Reset(service string) (string, error)

Reset restores platform workloads to the state recorded in the agyn-platform Helm release, discarding out-of-band modifications (devspace dev patches, manual kubectl edits). Only workload kinds are replaced: they are what dev tooling patches, and replacing Services would trip on immutable fields.

A plain `helm upgrade` cannot do this: Helm's three-way merge preserves live changes to fields the chart itself did not change between revisions. The stored release manifest piped through `kubectl replace` stomps the drift.

service filters the restore to workloads with that metadata.name ("" = all). Everything runs inside the VM (helm, kubectl, and the release state live there); python3 is guaranteed by cloud-init. Returns the kubectl output.

func ResolveVersion

func ResolveVersion(version string) (string, error)

ResolveVersion turns "latest" into a concrete version via the CDN's latest.json pointer. Concrete versions pass through unchanged.

func RollingWorkloads added in v0.17.0

func RollingWorkloads(limit int) []string

RollingWorkloads names the workloads still short of their replicas, for the detail line of an upgrade waiting on rollouts.

func RunScript added in v0.17.0

func RunScript(script string, args ...string) (string, error)

RunScript pipes a script the CLI carries into the guest and runs it there, returning its combined output.

Nothing is installed in the VM and no copy is left behind to drift from this caller. That is the whole reason these scripts live with the CLI: one that lives in the image can only be corrected by building a new image and recreating the VM, which is the operation `upgrade` exists to avoid.

func RunScriptProgress added in v0.17.0

func RunScriptProgress(script string, onDetail func(string), args ...string) (string, error)

RunScriptProgress runs a script that reports where it has got to, calling onDetail for each AGYN|detail| line it writes. Everything else is the script's own log and is returned.

Scripts that restart the cluster take minutes, and a step with a fixed label for that long cannot be told from a hang.

func RunScriptWithSecret added in v0.17.0

func RunScriptWithSecret(script string, secret io.Reader, onDetail func(string), args ...string) (string, error)

RunScriptWithSecret runs a script whose input is a credential.

The script is staged into the guest first, because stdin is the one channel that carries a secret without putting it in an argument list -- and the script itself would otherwise be occupying it. An argument list is readable by any user of the guest, and by anyone running ps on the host while the CLI works. The staged copy is mode 0700 under /run, which is tmpfs, and is removed whether or not the run succeeds.

func SetBootstrapToken

func SetBootstrapToken(token string, onDetail func(string)) (string, error)

SetBootstrapToken installs the token this host holds into the running VM and returns the script's log output. The value travels over the limactl channel, never the network, and is never read back: the host keeps the copy it generated. It is handed over on stdin rather than as an argument, so it is in neither machine's process list.

func SetIngressPort

func SetIngressPort(port int, onDetail func(string)) (string, error)

SetIngressPort tells the VM which port this host forwards, so the URLs it hands a browser are reachable.

The image bakes a default, but the port belongs to the host: the default may already be taken. Only browser-facing URLs are affected — everything inside the cluster, the OpenZiti advertised addresses included, uses an internal port that never changes.

func Shell

func Shell(args ...string) (string, error)

Shell runs a command inside the guest and returns its stdout.

func ShellStdin added in v0.2.17

func ShellStdin(stdin io.Reader, args ...string) (string, error)

ShellStdin runs a command inside the guest with stdin piped from the host.

Used to stream an image archive straight into the guest's container store rather than staging a multi-gigabyte file on a disk that may not have room for it.

func Start

func Start(stdout, stderr io.Writer, opts VMOptions) error

Start boots an existing instance, first applying any size the user has changed since it was created. Lima reads the port forwards, cpus and memory from the instance's own config, which only creation writes, so without this an edited setting is stored and silently never takes effect.

func Stop

func Stop(stdout, stderr io.Writer) error

Stop shuts the instance down.

func UninstallCA

func UninstallCA() error

UninstallCA removes the CA from the system trust store. Requires sudo.

func Use

func Use(name string)

Use fixes the VM this process acts on. Called once, from the command layer.

func WaitWorkloadsReady

func WaitWorkloadsReady(names []string) error

WaitWorkloadsReady blocks until the given deployments (or all in the platform namespace when names is empty) finish rolling out.

func WorkloadProgress added in v0.17.0

func WorkloadProgress() (ready, total int, err error)

WorkloadProgress counts the workloads that have reached their desired replica count.

Types

type Account added in v0.17.0

type Account struct {
	Label    string
	Username string
	Password string
}

Account is a sign-in the bundled provider ships with.

func BundledAccounts added in v0.17.0

func BundledAccounts() []Account

BundledAccounts returns the sign-ins to print, or nothing.

Nothing unless the VM runs the shipped Dex config: Keycloak's accounts are different, an install pointed at its own issuer has none of ours, and a VM whose dex.users were replaced would be handed credentials that do not work. Each of those is worse than printing no credentials at all, so the check is for the two accounts this CLI knows the passwords of.

type CAInfo

type CAInfo struct {
	Subject     string `json:"subject" yaml:"subject"`
	NotBefore   string `json:"not_before" yaml:"not_before"`
	NotAfter    string `json:"not_after" yaml:"not_after"`
	Fingerprint string `json:"fingerprint_sha256" yaml:"fingerprint_sha256"`
	Path        string `json:"path" yaml:"path"`
	Trusted     bool   `json:"trusted" yaml:"trusted"`
}

CAInfo describes the extracted local CA.

func InspectCA

func InspectCA() (CAInfo, error)

InspectCA returns details about the cached CA.

type Check added in v0.17.0

type Check struct {
	Name     string     `json:"name" yaml:"name"`
	State    CheckState `json:"state" yaml:"state"`
	Detail   string     `json:"detail,omitempty" yaml:"detail,omitempty"`
	Fix      string     `json:"fix,omitempty" yaml:"fix,omitempty"`
	Blocking bool       `json:"blocking" yaml:"blocking"`
	// contains filtered or unexported fields
}

Check is one preflight result.

func BlockingFailures added in v0.17.0

func BlockingFailures(checks []Check) []Check

BlockingFailures returns the checks that stop a start.

func Preflight added in v0.17.0

func Preflight(opts PreflightOptions) []Check

Preflight reports what would stop this host from running the platform VM.

It runs on every `agyn local start` and is all of `agyn local doctor`: a missing or too-old host tool is the most common reason a first run fails, and left to limactl the failure arrives as a tool error rather than a sentence naming what to install.

func (Check) Passed added in v0.17.0

func (c Check) Passed() bool

Passed reports whether a check is one that lets a start proceed.

func (Check) Tool added in v0.17.0

func (c Check) Tool() bool

Tool reports whether this check is a host tool, which is the only kind of failure `--install-deps` and `doctor --fix` can act on.

type CheckState added in v0.17.0

type CheckState string

CheckState is the outcome of one preflight check.

const (
	// CheckOK is a check that passed.
	CheckOK CheckState = "ok"
	// CheckMissing is a tool that is not installed.
	CheckMissing CheckState = "missing"
	// CheckOutdated is a tool that is installed but older than the minimum.
	CheckOutdated CheckState = "outdated"
	// CheckFailed is a non-tool condition that is not satisfied.
	CheckFailed CheckState = "failed"
	// CheckWarning is worth reporting and not worth refusing to start over.
	CheckWarning CheckState = "warning"
)

type Endpoint

type Endpoint struct {
	Name    string `json:"name" yaml:"name"`
	URL     string `json:"url" yaml:"url"`
	Healthy bool   `json:"healthy" yaml:"healthy"`
}

Endpoint is one platform URL exposed by the VM ingress.

func CheckEndpoints

func CheckEndpoints(endpoints []Endpoint) []Endpoint

CheckEndpoints probes each endpoint. The local CA is typically not in Go's trust store, so certificate validation is skipped; reachability and an HTTP response are what is being tested.

func Endpoints

func Endpoints(port int) []Endpoint

Endpoints returns the primary platform endpoints for the configured port.

type Installer added in v0.17.0

type Installer struct {
	// Key selects package names from a tool's map.
	Key string
	// Name is what the user calls it.
	Name string
	// contains filtered or unexported fields
}

Installer is the package manager this host has, if it has one.

func DetectInstaller added in v0.17.0

func DetectInstaller() *Installer

DetectInstaller returns the package manager on this host, or nil.

The CLI never installs a package manager: bootstrapping Homebrew is a several-minute, sudo-taking, machine-wide change that a platform CLI has no business making on someone's behalf. A machine without one is told what to install and by whom.

type Instance

type Instance struct {
	Exists bool   `json:"exists" yaml:"exists"`
	Status string `json:"status,omitempty" yaml:"status,omitempty"`
	Dir    string `json:"dir,omitempty" yaml:"dir,omitempty"`
}

Instance describes the managed Lima instance.

func GetInstance

func GetInstance() (Instance, error)

GetInstance reports the managed instance's state.

type PreflightOptions added in v0.17.0

type PreflightOptions struct {
	// Ports must be free. Only a VM being created needs this: an existing VM
	// already holds its own ports, and finding them taken by itself would
	// refuse every restart.
	Ports []int
	// Space checks room for an image and the VM created from it.
	Space bool
}

PreflightOptions narrow the checks to what a particular command needs.

type Readiness added in v0.17.0

type Readiness struct {
	// Endpoints answering through the host's forwarded port. The ingress
	// begins serving tens of seconds after the VM reports itself started.
	Endpoints []Endpoint
	// Organization is the id the platform assigned to the organization its
	// release declares. Provisioning completes after the endpoints answer, so
	// an endpoint check alone is not evidence that it has -- and this id is
	// what the profile records and every org-scoped command runs against.
	Organization string
	// Pending names what is not ready yet, for a caller to show.
	Pending []string
}

Readiness is the platform's own account of whether it can be used yet.

func CheckReadiness added in v0.17.0

func CheckReadiness(port int) Readiness

CheckReadiness probes both signals once.

func WaitForReady added in v0.17.0

func WaitForReady(port int, timeout time.Duration, progress func(detail string)) (Readiness, error)

WaitForReady blocks until the platform can be used, reporting what it is waiting on as that changes.

Returning when the endpoints answer is what left credential provisioning running against a platform that had not finished starting: the read it needs -- the assigned organization id -- lands after the ingress does.

func (Readiness) Missing added in v0.17.0

func (r Readiness) Missing() string

Missing describes what is still outstanding, for a timeout message.

func (Readiness) Ready added in v0.17.0

func (r Readiness) Ready() bool

Ready reports whether both readiness signals hold.

type Tool added in v0.17.0

type Tool struct {
	// Name is the binary as it must appear on PATH.
	Name string `json:"name" yaml:"name"`
	// Label is what a person calls it, when that differs from the binary.
	Label string `json:"label" yaml:"label"`
	// MinVersion is the oldest release the published lima.yaml and this CLI's
	// use of the tool are known to work with.
	MinVersion string `json:"minVersion,omitempty" yaml:"minVersion,omitempty"`
	// contains filtered or unexported fields
}

Tool is one host tool `agyn local` needs, and what it takes to get it.

func InstallableTools added in v0.17.0

func InstallableTools(checks []Check) []Tool

InstallableTools returns the tools behind failing checks — what `--install-deps` and `doctor --fix` would install.

func RequiredTools added in v0.17.0

func RequiredTools() []Tool

RequiredTools is what `agyn local start` cannot proceed without.

Minimums are the point of the version field: a tool that is present but too old passes a presence check and fails later inside limactl, in a message that names neither the tool's version nor the fix.

type UpgradeResult added in v0.17.0

type UpgradeResult struct {
	// Changed is true when a release moved, which is what makes the
	// browser-facing port need putting back.
	Changed bool
	// Migrated is true when the install was moved to a different identity
	// provider. Whoever ran the upgrade now signs in somewhere else, with
	// accounts that are not the ones they had.
	Migrated bool
}

UpgradePlatform moves the platform releases in the running VM to newer chart versions, leaving the VM and its data alone.

Upgrading by replacing the disk image would discard every database, thread and workload in the VM. That is the right way to get a clean machine — delete then start — but the wrong thing for "upgrade" to mean, because it is not reversible and destroys work the user did not ask to lose.

The script reports its progress as steps and sends everything Helm and kubectl say to log: a Helm upgrade that waits on rollouts takes minutes, and what the user asked was which versions moved, not what the admission webhook thinks of the release's AuthorizationPolicies. Returns whether any release moved. The caller acts on that: an upgrade rewrites every Deployment the charts own, including the browser-facing URLs that were pointed at this host's port outside the release. resume clears the revision an interrupted upgrade left in flight before upgrading, which is what stops Helm refusing it. UpgradeResult is what an upgrade did, for a caller deciding what to say afterwards.

func UpgradePlatform

func UpgradePlatform(steps *terminal.Steps, log io.Writer, platformVersion string, resume bool, ingressPort int) (UpgradeResult, error)

type VMOptions

type VMOptions struct {
	Port    int
	APIPort int
	CPUs    int
	Memory  string
}

VMOptions parametrize instance creation.

type Workload added in v0.17.0

type Workload struct {
	Name    string
	Ready   int
	Desired int
}

Workload is one deployment or statefulset and how far its rollout has got.

func Workloads added in v0.17.0

func Workloads() ([]Workload, error)

Workloads reads the platform's workloads from inside the VM, so a wait can say how far along it is rather than only that it is still waiting.

func (Workload) Rolling added in v0.17.0

func (w Workload) Rolling() bool

Rolling reports whether the workload is short of its desired replicas.

Jump to

Keyboard shortcuts

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