inspect

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT, MIT Imports: 10 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 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.

Variables

This section is empty.

Functions

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

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