Documentation
¶
Overview ¶
Package inventory keeps each host's cached instance inventory warm by refreshing it on a schedule, so UI/API reads are served without a live podman sweep and an unreachable host never stalls a request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EffectiveBootTimeout ¶ added in v1.0.36
EffectiveBootTimeout maps a configured boot-probe timeout to the value the poller will actually spend: anything <= 0 means defaultBootTimeout, never "no timeout" and never "expire instantly". Exported for the same reason EffectiveStatsTimeout is: server's startup budget check (statsBudgetWarning) has to reason about the same effective value the poller uses, not the raw (possibly zero) configured one.
func EffectiveStatsTimeout ¶ added in v1.0.29
EffectiveStatsTimeout maps a configured stats timeout to the value the poller will actually spend: anything <= 0 means defaultStatsTimeout, never "no timeout" (tick blocks the ticker, so an unbounded stats call would hang the whole poll loop) and never "expire instantly".
Exported because the zero-defaulting is not an internal detail: anything reasoning about the per-host budget from the outside — server's startup check that Timeout+StatsTimeout stays under Interval — has to reason about the same effective value, or a bare -container-stats-timeout=0 passes a check the poller then violates by 5s.
Types ¶
type BootConverger ¶ added in v1.0.36
type BootConverger interface {
// HostUptime returns hostID's current kernel uptime. ok is false when the
// host's podman cannot report it (e.g. too old, or a format this client
// doesn't parse) — callers must treat that as "unknown", never as "just
// booted".
HostUptime(ctx context.Context, hostID string) (uptime time.Duration, ok bool, err error)
// ReconcileSpecsOnHost re-creates any stored spec whose pod is missing.
// Deliberately tolerant (see the method's own doc comment): it logs and
// continues per-instance and never propagates an error, so calling it
// speculatively here is safe.
ReconcileSpecsOnHost(ctx context.Context, hostID string)
}
BootConverger detects a host reboot from its kernel uptime and re-converges that host's stored specs when one is detected. Implemented by *instance.Service: HostUptime delegates to podman.Client.HostUptime, and ReconcileSpecsOnHost is the same method server.go already runs once at daemon startup — this just gives it a second trigger, for the case that one-shot boot converge doesn't cover: the host reboots while podman-api keeps running (#231).
type Poller ¶
type Poller struct {
Svc Refresher
Interval time.Duration
Timeout time.Duration
// Stats, when non-nil, samples container resource usage on every tick,
// alongside the inventory refresh. Its failures are logged and otherwise
// ignored: reachability is the inventory refresh's to decide, and the
// Grafana alert rules all gate on podman_api_host_reachable.
Stats StatsRefresher
// StatsTimeout bounds one host's stats sample, independently of Timeout.
// Zero means defaultStatsTimeout — never "no timeout", so a caller that
// forgets to set it cannot hand the sampler an unbounded call. See tick for
// why this is a separate budget rather than a share of Timeout (#212).
StatsTimeout time.Duration
// Boot, when non-nil, probes each host's uptime on every tick and
// re-converges stored specs for a host whose uptime resets — i.e. it
// rebooted while podman-api kept running (#231). nil disables the check
// entirely: no extra calls, same as a nil Stats.
Boot BootConverger
// BootTimeout bounds one host's uptime probe when Boot is set,
// independently of Timeout — mirrors StatsTimeout, and for the same
// #212 reason: a slow-but-successful refresh must not starve this probe
// of its own budget by sharing the refresh's hctx. Zero means
// defaultBootTimeout.
//
// This bounds ONLY the lightweight HostUptime probe. The
// ReconcileSpecsOnHost call triggered by a detected reboot deliberately
// does NOT share this budget (#231 review finding #1): it is a full sweep
// of every stored spec on the host (PodInspect/GetSpec/GetTemplate/render/
// PlayKube per instance, plus an ingress reconcile), and a host with more
// than a handful of instances would have that recreation loop silently
// truncated by a 5s deadline meant for one cheap uptime read. It runs
// instead under the tick's own long-lived context (cancelled only on
// poller shutdown), the same convention server.go's one-shot startup boot
// converge already uses for "let a full per-host reconcile actually
// finish".
BootTimeout time.Duration
// contains filtered or unexported fields
}
Poller periodically refreshes every host's inventory into the service cache. It mirrors internal/prune.Scheduler: an immediate first pass so a fresh start warms within one cycle, per-tick panic recovery, a per-host timeout so one hung host can't bleed into the next cycle, and Wait() for clean shutdown.
func (*Poller) Start ¶
Start launches the ticker loop until ctx is cancelled. hostsFn returns the current host ids on each tick (so SIGHUP host reloads are picked up).
func (*Poller) StartVolumeUsage ¶ added in v1.0.28
func (p *Poller) StartVolumeUsage(ctx context.Context, hostsFn func() []string, r VolumeUsageRefresher, interval, timeout time.Duration)
StartVolumeUsage runs a separate, much slower loop that sizes each host's volumes. It is deliberately NOT part of tick(): podman's system df walks the whole store and can take minutes, so it must never delay an inventory refresh. Failures leave the previous sizing in place; staleness surfaces as podman_api_volume_usage_age_seconds rather than as a gap. It touches no reachability state, for the same reason the stats sampler doesn't.
type Refresher ¶
Refresher refreshes one host's cached inventory. Implemented by *instance.Service.RefreshHost.
type StatsRefresher ¶ added in v1.0.28
type StatsRefresher interface {
RefreshHostStats(ctx context.Context, host string) error
// DropHostStats discards the host's cached samples. Called when the host is
// not going to be sampled at all. No context: it does no I/O.
DropHostStats(host string)
}
StatsRefresher samples one host's container resource usage, or retires the samples it already holds. Implemented by *instance.Service.
Both methods are required, not optional: a sampler that can be skipped but not retired freezes a down host's series at their last value. Keeping them on one interface makes that a compile error rather than a silent metrics bug.