cloudmeta

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cloudmeta reads the provider, region and zone a machine runs in from the link-local metadata service of the cloud it sits on (AWS IMDSv2, Google Cloud, Azure, Hetzner, DigitalOcean). Detection is best effort: a machine with no metadata service (a home server) yields no result and the caller falls back to labels typed by the operator.

Index

Constants

View Source
const (
	EnvTimeout  = "APP_AGENT_METADATA_TIMEOUT"
	EnvDisable  = "APP_AGENT_METADATA_DISABLE"
	EnvProvider = "APP_NODE_PROVIDER"
	EnvRegion   = "APP_NODE_REGION"
	EnvZone     = "APP_NODE_ZONE"
)

Environment variables read by FromEnv.

View Source
const (
	SourceMetadata = "metadata"
	SourceEnv      = "env"
)

Sources of a detected Info.

Variables

This section is empty.

Functions

func LabelValue

func LabelValue(s string) string

LabelValue makes s a valid node label value, or "" when nothing usable remains.

Types

type Bases

type Bases struct {
	AWS, GCP, Azure, Hetzner, DigitalOcean string
}

Bases are the metadata service roots, overridable so tests can point each provider at a fake server.

func DefaultBases

func DefaultBases() Bases

DefaultBases are the real link-local endpoints.

type Config

type Config struct {
	Client  *http.Client
	Bases   Bases
	Timeout time.Duration
	// Override wins over anything detected and is how an operator labels a
	// machine that has no metadata service.
	Override Info
	Disabled bool
}

Config drives Detect.

func FromEnv

func FromEnv(lookup func(string) (string, bool)) Config

FromEnv builds a Config from the process environment.

func SystemConfig

func SystemConfig() Config

SystemConfig is FromEnv over os.LookupEnv.

type Info

type Info struct {
	Provider   string
	Region     string
	Zone       string
	InstanceID string
	Source     string
}

Info is where a machine runs. Empty fields were not reported.

func Detect

func Detect(ctx context.Context, cfg Config) Info

Detect applies the operator override on top of the first provider whose metadata service answers. Providers are probed concurrently but resolved in a fixed order, so a host that answers on more than one gives a stable result.

func (Info) Found

func (i Info) Found() bool

Found reports whether anything was detected.

Jump to

Keyboard shortcuts

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