monitor: see unikernel VMs + use canonical container naming

Two drift-reporting bugs:
1. The monitor listed only the podman runtime, so unikernel VMs always
   showed observed=unknown (false drift). It now takes a ContainerLister
   and the agent passes a merged lister (containers + VMs), mirroring
   listAllContainers.
2. The monitor computed the lookup name as service+"-"+component, which
   is wrong when component==service (the name collapses to just the
   service, e.g. "uktest"/"mc-proxy"). It now uses the canonical
   naming.ContainerNameFor — extracted to a shared package so the agent
   and monitor can't disagree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Kyle Isom
2026-06-11 12:48:31 -07:00
parent 84dd897bcd
commit 4a55972455
6 changed files with 125 additions and 42 deletions

View File

@@ -2,6 +2,7 @@ package agent
import (
"context"
"log/slog"
"os"
"os/exec"
"path/filepath"
@@ -54,21 +55,38 @@ func (a *Agent) runtimeFor(rt string) runtime.Runtime {
return a.Runtime
}
// listAllContainers returns the observed state across every configured
// runtime (containers + unikernel VMs) so reconciliation, status, and drift
// detection see the whole picture.
func (a *Agent) listAllContainers(ctx context.Context) ([]runtime.ContainerInfo, error) {
infos, err := a.Runtime.List(ctx)
// mergedLister lists observed containers across the container runtime and
// (optionally) the unikernel runtime, so reconciliation, status, drift
// detection, and the monitor see VMs and containers uniformly. It satisfies
// the small lister interface the monitor consumes.
type mergedLister struct {
primary runtime.Runtime
extra runtime.Runtime // unikernel runtime; may be nil
logger *slog.Logger
}
// List returns containers from the primary runtime plus, when configured,
// unikernel VMs. A failure to list VMs is logged but not fatal — the
// container view still reconciles.
func (m mergedLister) List(ctx context.Context) ([]runtime.ContainerInfo, error) {
infos, err := m.primary.List(ctx)
if err != nil {
return nil, err
}
if a.Unikernel != nil {
vms, vmErr := a.Unikernel.List(ctx)
if m.extra != nil {
vms, vmErr := m.extra.List(ctx)
if vmErr == nil {
infos = append(infos, vms...)
} else if a.Logger != nil {
a.Logger.Warn("list unikernel VMs failed", "err", vmErr)
} else if m.logger != nil {
m.logger.Warn("list unikernel VMs failed", "err", vmErr)
}
}
return infos, nil
}
// listAllContainers returns the observed state across every configured
// runtime (containers + unikernel VMs) so reconciliation, status, and drift
// detection see the whole picture.
func (a *Agent) listAllContainers(ctx context.Context) ([]runtime.ContainerInfo, error) {
return mergedLister{primary: a.Runtime, extra: a.Unikernel, logger: a.Logger}.List(ctx)
}