inspect

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT, MIT Imports: 12 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

The CONTROL STACK's own runtime — traefik, pstack, the optional advanced UI — as an operator's page shows it.

The point of this view is the two numbers nothing surfaced before: RESTART COUNT and OOM-KILLED. A Traefik that restarts loses its in-memory ACME challenge tokens, so certificates quietly stop issuing while every container reports healthy — an incident that was diagnosed from a default certificate's notBefore timestamp because the restart itself was visible nowhere.

One mutation lives here too, and one refusal: RestartControlService restarts any control container EXCEPT pstack's own. Recreating the container performing the operation kills the operation, and if the new image is broken, the thing that could have repaired the host died with it — the rule the control template's header states, enforced by name instead of by distance.

And two reads of what the control stack runs, never of a setting. LokiPushURL: whether a deploy injects a loki logging block comes from the running loki container's label, so `pstack up` on the host and the API always agree, and nothing needs syncing when `pstack logging` switches. GrafanaOn: whether the API answers Grafana sign-in and names Grafana in /api/health comes from a grafana container being there, so no setting can claim a Grafana this host does not run.

Package inspect answers "what is actually running, and what was Traefik actually told about it".

WHY THIS EXISTS. "The hostname does not work" was undiagnosable from this tool. The registry knows what you *submitted*; `compose ps` knows what is *running*; the reason a request 404s lives in neither — it is in the container's Traefik labels, which pstack never writes. Every check below is one of the five rules in examples/docker-compose.preview.yml, turned from prose into a finding.

NEVER RETURN A RAW INSPECT. `docker inspect` includes Config.Env — the container's whole environment, where database passwords live. Each field is picked out by name, and label values go through redact.RedactText, because a basicauth users label is a credential too.

SWARM. A swarm stack's containers carry com.docker.stack.namespace; Traefik's routes come from SERVICE labels; a task may run on another node, listed from `docker stack ps` with remote:true. Only tasks whose desired state is `running` count — swarm replaces a failed task rather than restarting the container, so `docker ps -a` on a manager accumulates corpses.

AND A SWARM ROUTE'S TARGET IS THE SERVICE'S VIP. `docker inspect` gives a task container's own ingress IP, but only for a task on THIS node — and with the default (vip) endpoint mode that is not the address Traefik dials anyway. The manager knows the one that is: Endpoint.VirtualIPs on the `docker service inspect` we already make, node-independent. Every fallback below degrades to a NAMED reason (RouteInfo.TargetReason) rather than to a guess: this page's whole job is to stop saying "not on the ingress network" about a container nobody looked at.

Index

Constants

View Source
const (
	StackLabel   = "com.docker.stack.namespace"
	ServiceLabel = "com.docker.swarm.service.name"
	TaskLabel    = "com.docker.swarm.task.id"
	NodeLabel    = "com.docker.swarm.node.id"
	Ingress      = "preview-ingress"
)

The labels docker stamps. Mirrored in internal/swarm; docker's, not ours.

View Source
const ControlProject = initctl.ControlProject

ControlProject is initctl's — the project `pstack init` actually creates — re-exported, never a second literal: this label is the restart's entire trust boundary, and a drifted copy would leave `pstack-control` an unclaimed namespace any deployment could squat.

View Source
const NotAllocated = "never allocated: swarm gave it no address or machine. On the manager, " +
	"`journalctl -u docker | grep 'available IP'` shows whether a network ran out of addresses"

NotAllocated is what pstack says about a swarm task stuck in `New`: created, but never given an address or a machine. A task normally leaves `New` within a second; one that stays is waiting on swarm's allocator, which in practice means a network with no addresses left. Swarm writes the reason only to the manager's docker log — `docker service ps` shows no error at all — so the sentence points there. One copy, for readiness and for /api/signals.

Variables

View Source
var (
	ErrRestartSelf = errors.New(`refusing to restart "pstack": it is the container answering this request. Recreating it kills the operation in flight, and if its image is broken, the thing that could repair this host dies with it. Restart it from the host: docker compose -p pstack-control restart pstack`)
	ErrNoDocker    = errors.New("docker did not answer")
	ErrNoService   = errors.New("no such control service")
)

The three ways RestartControlService refuses, for the route to map onto statuses.

Functions

func ControlUI added in v0.43.0

func ControlUI(r exec.Runner) string

ControlUI is "hearth" when the control stack's advanced-ui container carries the hearth label, else "". Read from the running container: the service name is the same in both container modes.

func GrafanaOn added in v0.40.0

func GrafanaOn(r exec.Runner) bool

GrafanaOn reports whether the control project has a `grafana` container. `-a`, as LokiPushURL: a Grafana that is restarting is still this host's, and `pstack logging off` removes the container.

func GrafanaOnChecked added in v0.40.0

func GrafanaOnChecked(r exec.Runner) (on bool, ok bool)

GrafanaOnChecked is GrafanaOn plus an ok flag, false when docker did not answer, so a caller that polls on a timer (server.go's reindexLoop) can keep its last known value instead of flipping to off on one missed `docker ps`.

func HostsFromRule

func HostsFromRule(rule string) []string

HostsFromRule pulls hostnames out of a Traefik rule: `Host(a, b)` yields both; a HostRegexp yields `(pattern) <regexp>`.

func LokiPushURL added in v0.40.0

func LokiPushURL(r exec.Runner) string

LokiPushURL is the URL deploys put in every injected logging block. It is the `pstack.logging.push-url` label that `pstack init --logging loki` renders onto the control stack's loki service, read from the container the way DetectChallenge reads Traefik's flags. "" means logging is off: docker did not answer, or no control container is the loki service with the label.

`-a` (idsByLabel) is deliberate: a Loki that is restarting must not flip deploys between injected and not. `pstack logging off` re-runs init, whose `up --remove-orphans` removes the container, so it stops being found.

func RestartControlService added in v0.35.0

func RestartControlService(r exec.Runner, service string) (string, error)

RestartControlService restarts one control-stack container by its compose service name and returns the container's name. `pstack` is refused — see the package comment.

func TaskState

func TaskState(current string) string

TaskState is `Running 3 minutes ago` → running; Failed/Rejected → restarting (swarm is about to replace it); Shutdown/Complete → exited.

Types

type AllRouters

type AllRouters struct {
	Reachable bool
	Routes    []HostRoute
	ByName    map[string][]string
}

AllRouters is every Traefik router declared by any container on the host. Two uses: the global collision check, and the Routing page.

func AllTraefikRouters

func AllTraefikRouters(r exec.Runner) AllRouters

AllTraefikRouters reads every traefik.enable=true container and service.

type Challenge

type Challenge string

Challenge is which ACME challenge the host's Traefik runs.

const (
	HTTP01  Challenge = "http01"
	DNS01   Challenge = "dns01"
	Unknown Challenge = "unknown"
	// DNSPersist: a stored wildcard beside Traefik's dynamic config covers every preview. Never
	// detected HERE (DetectChallenge reads argv, and Traefik's argv keeps its init-time flags in
	// this mode) — the server passes it in when the stored wildcard exists.
	DNSPersist Challenge = "dns-persist-01"
)

func DetectChallenge

func DetectChallenge(r exec.Runner) Challenge

DetectChallenge reads which ACME challenge the host's Traefik runs from its own flags. It decides an OPPOSITE rule for per-PR routers, so reading the running container beats asking.

type ContainerInfo

type ContainerInfo struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Service       *string           `json:"service"`
	Image         string            `json:"image"`
	State         string            `json:"state"`
	Health        *string           `json:"health"`
	ExitCode      *int64            `json:"exitCode"`
	RestartCount  int64             `json:"restartCount"`
	Networks      []string          `json:"networks"`
	IngressIP     *string           `json:"ingressIp"`
	Ports         []PortMap         `json:"ports"`
	TraefikLabels map[string]string `json:"traefikLabels"`
	StartedAt     *int64            `json:"startedAt"`
	Node          *string           `json:"node"`
	Remote        bool              `json:"remote"`
	// Job marks the SYNTHESISED row that stands for a one-shot swarm service's verdict — its id and
	// name are the service's, and no container answers to them, so start/stop/exec can only fail.
	// Plain bool without omitempty (Go rule 2): false must serialize.
	Job bool `json:"job"`
}

ContainerInfo is one container as the deployment page shows it.

type ControlContainer added in v0.35.0

type ControlContainer struct {
	ContainerInfo
	// OOMKilled is docker's own flag: the LAST exit was the kernel's, not the process's. Paired
	// with RestartCount it answers "why did traefik restart at noon" without an SSH session.
	OOMKilled bool `json:"oomKilled"`
	// MemLimitBytes is the container's limit, nil when unlimited — the denominator OOMKilled needs.
	// Docker itself says 0 for "no limit"; that is normalized to nil here so the wire carries ONE
	// encoding of the fact (rule 2: a tri-state is a pointer, and its nil must mean something).
	MemLimitBytes *int64 `json:"memLimitBytes"`
}

ControlContainer is ContainerInfo plus the two fields that only matter for the control stack.

type ControlView added in v0.35.0

type ControlView struct {
	Containers []ControlContainer `json:"containers"`
	// Reachable: false means docker did not answer — every field above is "unknown", never "empty".
	Reachable bool `json:"reachable"`
}

ControlView is what GET /api/control/runtime answers.

func ControlRuntime added in v0.35.0

func ControlRuntime(r exec.Runner) ControlView

ControlRuntime lists the control stack's containers. Same probes DeploymentRuntime uses, scoped by the pinned project label.

type Finding

type Finding struct {
	Level   string `json:"level"` // error | warn | info
	Message string `json:"message"`
}

Finding is one diagnosis. Short, specific, names the fix.

type HostRoute

type HostRoute struct {
	RouteInfo
	Project *string `json:"project"`
}

HostRoute is a route with the compose project (or swarm stack) that declares it.

type PortMap

type PortMap struct {
	ContainerPort int64   `json:"containerPort"`
	Protocol      string  `json:"protocol"`
	HostPort      *string `json:"hostPort,omitempty"`
}

PortMap is one published port mapping.

type RouteInfo

type RouteInfo struct {
	Router       string   `json:"router"`
	Container    string   `json:"container"`
	Rule         string   `json:"rule"`
	Hosts        []string `json:"hosts"`
	Service      *string  `json:"service"`
	Port         *int64   `json:"port"`
	Entrypoints  *string  `json:"entrypoints"`
	TLS          bool     `json:"tls"`
	Certresolver *string  `json:"certresolver"`
	Priority     *string  `json:"priority"`
	Target       *string  `json:"target"`
	// TargetReason says WHY Target is nil, so the page can state a fact instead of the single guess
	// it used to make about every one of these. "" when Target is set; otherwise exactly one of
	// "no-port" (the router declares no loadbalancer.server.port), "not-on-ingress" (the subject is
	// POSITIVELY not attached to preview-ingress) and "unknown-node" (nothing here can know the
	// address: a swarm task on another node, or network names docker would not resolve). Plain
	// string without omitempty (Go rule 2) — "" must serialize.
	TargetReason string `json:"targetReason"`
}

RouteInfo is a Traefik router as declared by labels, joined to the service it points at.

func RoutesFromLabels

func RoutesFromLabels(container string, labels map[string]string, ingressIP *string, onIngress *bool) []RouteInfo

RoutesFromLabels turns one container's Traefik labels into routers joined to their service ports. A router with no explicit .service is left nil rather than guessed. Routers are returned in the order their first label was seen — labels are iterated in sorted order, so the result is stable.

`onIngress` is whether the subject is attached to preview-ingress, and NIL means the caller could not determine it. That nil is the whole point of this parameter: a missing target used to be rendered as "not on the ingress network" whether or not anyone had looked, which under swarm was false on every row. TargetReason separates the three facts.

type Runtime

type Runtime struct {
	Stack      string          `json:"stack"`
	Containers []ContainerInfo `json:"containers"`
	// Services is every service the stack has, by name. Under swarm a service whose tasks have all
	// failed has NO container row — swarm keeps only the tasks it still wants running — so this is
	// the one place its name survives, and the only way to offer its logs, which `docker service
	// logs` can still read. Compose lists every container, exited or not: names come from those.
	Services  []string    `json:"services"`
	Routes    []RouteInfo `json:"routes"`
	Findings  []Finding   `json:"findings"`
	Challenge Challenge   `json:"challenge"`
	// Reachable: true when docker answered. False means every field above is "unknown", never "empty".
	Reachable bool `json:"reachable"`
}

Runtime is everything the deployment page needs.

func DeploymentRuntime

func DeploymentRuntime(a RuntimeArgs) Runtime

DeploymentRuntime is everything the deployment page needs: containers, routes, findings.

type RuntimeArgs

type RuntimeArgs struct {
	Stack  string
	Runner exec.Runner
	// Challenge, when known; "" means detect.
	Challenge Challenge
	// AllRouters is router name → container names across the WHOLE host, for the collision check.
	AllRouters map[string][]string
	// Orchestrator decides which labels name this stack's containers. Default compose.
	Orchestrator spec.Orchestrator
}

RuntimeArgs parameterise DeploymentRuntime.

type SwarmService

type SwarmService struct {
	ID            string
	Name          string // `<stack>_<service>`
	Service       string // the compose service name
	Stack         *string
	Image         string
	Networks      []string
	TraefikLabels map[string]string
	UpdatedAt     *int64
	// IngressIP is the service's VIP on preview-ingress, nil when it has none (dnsrr) or the
	// network list could not be read.
	IngressIP *string
	// NetworksKnown is false when a network id did not resolve to a name, so Networks holds a raw
	// id and "this is not the ingress network" is NOT established.
	NetworksKnown bool
}

SwarmService is a swarm service with its routing labels.

func (SwarmService) OnIngress added in v0.32.0

func (s SwarmService) OnIngress() *bool

OnIngress is whether the service is attached to preview-ingress — nil for "could not determine" (invariant 11). "Not attached" is a diagnosis with a fix attached to it; it has to be measured.

Jump to

Keyboard shortcuts

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