yangerd: Fix containers

This commit is contained in:
Mattias Walström
2026-06-27 08:41:22 +02:00
parent ce4184e048
commit 62b890f7b6
2 changed files with 15 additions and 7 deletions
+12 -4
View File
@@ -362,12 +362,20 @@ func (c *ContainerCollector) container(ctx context.Context, ps map[string]interf
"status": asString(ps["Status"]),
}
cmd := strings.Join(asStringSlice(ps["Command"]), " ")
if cmd != "" {
out["command"] = cmd
inspect := c.podmanInspect(ctx, name)
// Report the actual running command line as the config-false
// "cmdline" leaf (an unrestricted string), built from inspect's
// Path + Args like the legacy yanger collector. Do NOT report it
// into the config-true "command" leaf: that leaf has a restrictive
// pattern and a real command line (e.g. one containing "&&" or
// quotes) fails YANG validation, which rejects the entire
// containers subtree on read.
if path := asString(inspect["Path"]); path != "" {
parts := append([]string{path}, asStringSlice(inspect["Args"])...)
out["cmdline"] = strings.Join(parts, " ")
}
inspect := c.podmanInspect(ctx, name)
if net := c.network(ps, inspect); len(net) > 0 {
out["network"] = net
}
@@ -60,7 +60,7 @@ func TestContainerBasicInfo(t *testing.T) {
"Ports": []
}
]`),
"podman inspect web": []byte(`[{}]`),
"podman inspect web": []byte(`[{"Path":"nginx","Args":["-g","daemon off;"]}]`),
"podman stats --no-stream --format json --no-reset web": []byte(`[]`),
},
Errors: map[string]error{},
@@ -87,8 +87,8 @@ func TestContainerBasicInfo(t *testing.T) {
if c["status"] != "Up 2 hours" {
t.Fatalf("status mismatch: %v", c["status"])
}
if c["command"] != "nginx -g daemon off;" {
t.Fatalf("command mismatch: %v", c["command"])
if c["cmdline"] != "nginx -g daemon off;" {
t.Fatalf("cmdline mismatch: %v", c["cmdline"])
}
if c["running"] != true {
t.Fatalf("running expected true, got %v", c["running"])