local

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 22 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 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 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 EnsureImage

func EnsureImage(version, arch string, progress io.Writer) (string, error)

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

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 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 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 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

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 SetBootstrapToken

func SetBootstrapToken(token 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.

func SetIngressPort

func SetIngressPort(port int) (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 UpgradePlatform

func UpgradePlatform(stdout, stderr io.Writer, platformVersion, appsVersion string) error

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

func WaitForPlatform(port int, timeout time.Duration) bool

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

func WaitWorkloadsReady(names []string) error

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.

func InspectCA

func InspectCA() (CAInfo, error)

InspectCA returns details about the cached 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

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 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 VMOptions

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

VMOptions parametrize instance creation.

Jump to

Keyboard shortcuts

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