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:
@@ -227,6 +227,45 @@ func TestMonitorTickStateChange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestMonitorTickCollapsedName guards the naming convention: when a
|
||||
// component's name equals its service, the container/VM name collapses to just
|
||||
// the service (e.g. "uktest", not "uktest-uktest"). The monitor must use
|
||||
// naming.ContainerNameFor to look it up, or it would report a running
|
||||
// component as "unknown" and raise false drift.
|
||||
func TestMonitorTickCollapsedName(t *testing.T) {
|
||||
db := openTestDB(t)
|
||||
logger := testLogger()
|
||||
cfg := testMonitorConfig()
|
||||
|
||||
if err := registry.CreateService(db, "uktest", true, ""); err != nil {
|
||||
t.Fatalf("create service: %v", err)
|
||||
}
|
||||
if err := registry.CreateComponent(db, ®istry.Component{
|
||||
Name: "uktest", Service: "uktest", Image: "img:v1",
|
||||
Restart: "unless-stopped", DesiredState: "running", ObservedState: "unknown",
|
||||
}); err != nil {
|
||||
t.Fatalf("create component: %v", err)
|
||||
}
|
||||
|
||||
// The runtime reports the collapsed name, as podman/QEMU actually do.
|
||||
rt := &fakeRuntime{
|
||||
containers: []runtime.ContainerInfo{
|
||||
{Name: "uktest", State: "running"},
|
||||
},
|
||||
}
|
||||
|
||||
m := New(db, rt, cfg, "test-node", logger)
|
||||
m.tick()
|
||||
|
||||
comp, err := registry.GetComponent(db, "uktest", "uktest")
|
||||
if err != nil {
|
||||
t.Fatalf("get component: %v", err)
|
||||
}
|
||||
if comp.ObservedState != "running" {
|
||||
t.Fatalf("observed state: got %q, want %q (collapsed name not resolved)", comp.ObservedState, "running")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMonitorStartStop(t *testing.T) {
|
||||
db := openTestDB(t)
|
||||
logger := testLogger()
|
||||
|
||||
Reference in New Issue
Block a user