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
- Variables
- func Arch() (string, error)
- func BaseURL() string
- func CAPath() (string, error)
- func CertsDir() (string, error)
- func CheckAPIPort(apiPort int) error
- func CreateAndStart(imageDir string, opts VMOptions, stdout, stderr io.Writer) error
- func Delete(stdout, stderr io.Writer) error
- func Dir() (string, error)
- func DiskFileName(arch string) string
- func EnsureCA() (string, error)
- func EnsureImage(version, arch string, progress io.Writer) (string, error)
- func ExtractCA() error
- func FetchKubeconfig(apiPort int) (map[string]any, error)
- func GatewayURL(port int) string
- func GenerateBootstrapToken() (string, error)
- func ImageDir(version, arch string) (string, error)
- func InstallCA() error
- func InstanceName() string
- func IsBootstrapToken(token string) bool
- func KubeContextName() string
- func LimaHome() (string, error)
- func MergeKubeconfig(path string, fetched map[string]any) error
- func OrganizationID() (string, error)
- func Reset(service string) (string, error)
- func ResolveVersion(version string) (string, error)
- func SetBootstrapToken(token string) (string, error)
- func SetIngressPort(port int) (string, error)
- func Shell(args ...string) (string, error)
- func Start(stdout, stderr io.Writer, opts VMOptions) error
- func Stop(stdout, stderr io.Writer) error
- func UninstallCA() error
- func UpgradePlatform(stdout, stderr io.Writer, platformVersion, appsVersion string) error
- func Use(name string)
- func WaitForPlatform(port int, timeout time.Duration) bool
- func WaitWorkloadsReady(names []string) error
- type CAInfo
- type Dependency
- type Endpoint
- type Instance
- type VMOptions
Constants ¶
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 )
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 ¶
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 BaseURL ¶
func BaseURL() string
BaseURL returns the CDN endpoint, honoring the environment override.
func CertsDir ¶
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 ¶
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 CreateAndStart ¶
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 DiskFileName ¶
DiskFileName returns the qcow2 file name for an architecture.
func EnsureImage ¶
EnsureImage makes sure the decompressed disk for version/arch exists locally, downloading and verifying it if needed. Returns the image directory. Progress messages go to progress (may be nil).
func ExtractCA ¶
func ExtractCA() error
ExtractCA reads the CA certificate from the running VM and caches it, overwriting any previous copy.
func FetchKubeconfig ¶
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 ¶
GatewayURL returns the API endpoint the CLI talks to. It shares the ingress port with the browser endpoints; only the hostname differs.
func GenerateBootstrapToken ¶
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 InstallCA ¶
func InstallCA() error
InstallCA adds the cached CA to the system trust store. Requires sudo.
func InstanceName ¶
func InstanceName() string
InstanceName is the Lima instance this process acts on.
func IsBootstrapToken ¶
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 ¶
LimaHome returns the LIMA_HOME used for the managed instance so all VM state lives under ~/.agyn/local.
func MergeKubeconfig ¶
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 ¶
OrganizationID reads the organization the image provisioned. It is recorded in a ConfigMap when the platform is baked, so it is readable as soon as the API server answers — before the Gateway itself serves traffic — and it is read through limactl rather than over the network, like the CA.
func Reset ¶
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 ¶
ResolveVersion turns "latest" into a concrete version via the CDN's latest.json pointer. Concrete versions pass through unchanged.
func SetBootstrapToken ¶
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.
func SetIngressPort ¶
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 Start ¶
Start boots an existing instance, first applying any size the user has changed since it was created. Lima reads 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 UninstallCA ¶
func UninstallCA() error
UninstallCA removes the CA from the system trust store. Requires sudo.
func UpgradePlatform ¶
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.
Output is streamed rather than captured: a Helm upgrade that waits for rollouts takes minutes, and silence for minutes is indistinguishable from a hang.
func Use ¶
func Use(name string)
Use fixes the VM this process acts on. Called once, from the command layer.
func WaitForPlatform ¶
WaitForPlatform polls the platform endpoints until they all answer or the timeout elapses. The VM reports "started" as soon as the guest boots, but the in-cluster ingress takes tens of seconds more to serve traffic.
func WaitWorkloadsReady ¶
WaitWorkloadsReady blocks until the given deployments (or all in the platform namespace when names is empty) finish rolling out.
Types ¶
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.
type Dependency ¶
type Dependency struct {
Name string `json:"name" yaml:"name"`
Found bool `json:"found" yaml:"found"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Fix string `json:"fix,omitempty" yaml:"fix,omitempty"`
Optional bool `json:"optional" yaml:"optional"`
}
Dependency describes one host tool required by `agyn local`.
func CheckDependencies ¶
func CheckDependencies() []Dependency
CheckDependencies inspects the host for the tools `agyn local` needs.
func MissingRequired ¶
func MissingRequired(deps []Dependency) []Dependency
MissingRequired returns the required dependencies that were not found.
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 ¶
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.
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 ¶
GetInstance reports the managed instance's state.