runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package runtime detects the container/process runtime (Kubernetes, Docker, Podman, systemd-managed, or plain binary) and exposes a unified Info so the rest of the framework can attach identity metadata to logs/metrics/traces without caring where the process runs.

This package is the runtime-agnostic successor to k8s/podinfo:

  • On Kubernetes it reads the downward-API env vars (POD_NAME, POD_NAMESPACE, POD_IP, NODE_NAME, SERVICE_ACCOUNT) plus the container ID from cgroups.
  • On Docker / Podman it reads the container ID from cgroups + HOSTNAME.
  • On systemd it reads INVOCATION_ID + NOTIFY_SOCKET presence to identify the unit.
  • On bare Linux it falls back to os.Hostname().

`k8s/podinfo` remains as a k8s-only view for packages that want just the k8s fields; new code should prefer `container/runtime`.

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module("golusoris.container.runtime",
	fx.Provide(Detect),
)

Module provides Info via fx.

Functions

This section is empty.

Types

type Info

type Info struct {
	// Runtime is the detected platform.
	Runtime Runtime
	// Hostname is os.Hostname(). Always populated.
	Hostname string
	// ContainerID is the 12+ char container ID from /proc/self/cgroup,
	// or empty if the runtime doesn't expose it.
	ContainerID string

	// PodName, Namespace, PodIP, NodeName, ServiceAccount, ContainerName,
	// ContainerImage: populated on Kubernetes via the downward API.
	PodName        string
	Namespace      string
	PodIP          string
	NodeName       string
	ServiceAccount string
	ContainerName  string
	ContainerImage string

	// SystemdUnit is populated when Runtime == RuntimeSystemd, from the
	// SYSTEMD_UNIT env var (if set by the unit file) or falls back to the
	// INVOCATION_ID.
	SystemdUnit string
}

Info is the unified identity of the running process.

func Detect

func Detect() Info

Detect inspects the process environment + /proc + well-known files and returns a populated Info. Never errors: unknown details are left empty.

type Runtime

type Runtime string

Runtime identifies the container/process platform.

const (
	RuntimeK8s     Runtime = "kubernetes"
	RuntimeDocker  Runtime = "docker"
	RuntimePodman  Runtime = "podman"
	RuntimeSystemd Runtime = "systemd"
	RuntimeBare    Runtime = "bare"
)

Runtime values.

Jump to

Keyboard shortcuts

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