agent

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 15 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 agent runs gcpemu helper processes inside containers the emulator launches (GKE node metadata proxy, Cloud SQL server-side proxy). The emulator copies its own static binary into the container and starts it with GCPEMU_AGENT=<name>; Main dispatches to the registered agent.

Index

Constants

View Source
const BinaryEnv = "GCPEMU_AGENT_BINARY"

BinaryEnv overrides the binary copied into containers (tests set it to a CGO_ENABLED=0 build of ./cmd/gcpemu). See Resolver.

View Source
const ContainerPath = "/gcpemu/gcpemu"

ContainerPath is where the binary is placed inside containers.

View Source
const EnvVar = "GCPEMU_AGENT"

EnvVar selects the agent to run.

Variables

View Source
var ImageRepos = []string{"ghcr.io/linuxuser586/gcpemu", "docker.io/linuxuser586/gcpemu"}

ImageRepos are the repositories of the published image, tried in order for a release build's binary (NFR-PORT-004). The release workflow tags vX.Y.Z as X.Y.Z.

Functions

func BuildForTests

func BuildForTests(moduleRoot, dir, arch string) (string, error)

BuildForTests compiles ./cmd/gcpemu for linux/arch with CGO_ENABLED=0 into dir (once per process) and sets GCPEMU_AGENT_BINARY. moduleRoot is the repository root; arch is the runtime's, or "" for the host's.

go test runs packages in parallel, each building to the same path, so the build goes to a directory of its own and is renamed into place: the shared path only ever holds a whole binary. On Windows the rename fails while another package is copying that binary into a container; it is retried, and this process falls back to its own build if it never succeeds.

func Main

func Main()

Main runs the selected agent and exits if GCPEMU_AGENT is set; otherwise it returns immediately. Call it first thing in main (and in TestMain of packages whose tests start agents in-process).

func Register

func Register(name string, f Func)

Register installs an agent; call it from an init function.

func Release added in v0.6.0

func Release(version string) bool

Release reports whether version is a release build's (exactly vX.Y.Z).

Types

type Func

type Func func(ctx context.Context, args []string) error

Func is an agent entry point. It runs until ctx is cancelled (SIGTERM).

type Images added in v0.6.0

type Images interface {
	// ImageFile pulls ref for platform ("linux/arm64") and returns the
	// contents of file in it.
	ImageFile(ctx context.Context, ref, platform, file string) ([]byte, error)
}

Images is the part of the container runtime Resolver copies a release build's binary out of the published image with.

type Resolver added in v0.6.0

type Resolver struct {
	// Arch is the runtime's GOARCH; "" means the host's.
	Arch string
	// Version is the emulator's version (instance.Version).
	Version string
	// CacheDir holds binaries copied out of the published image; ""
	// disables the cache and the pull.
	CacheDir string
	// Offline skips the pull.
	Offline bool
	// Images pulls the published image; nil skips the pull.
	Images Images
	// contains filtered or unexported fields
}

Resolver finds a static linux gcpemu binary for the container runtime's architecture, to copy into Managed containers (ADR 0005). The host's own executable is used when the host is linux on that architecture. Otherwise the binary is, in order: $GCPEMU_AGENT_BINARY; a sibling gcpemu-linux-<arch> next to the executable; the cache at <CacheDir>/<Version>/linux-<arch>/gcpemu; and, for a release build (Version exactly vX.Y.Z), the one in the published image X.Y.Z, which is then cached.

func (*Resolver) Binary added in v0.6.0

func (r *Resolver) Binary(ctx context.Context) (string, error)

Binary returns the binary's path. A found binary is remembered; a failure is not, so a later call retries the pull.

Jump to

Keyboard shortcuts

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