Skip to content

Commit 71d50ea

Browse files
committed
yangerd: Fix containers
1 parent e2f212c commit 71d50ea

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/yangerd/internal/collector/containers.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,20 @@ func (c *ContainerCollector) container(ctx context.Context, ps map[string]interf
362362
"status": asString(ps["Status"]),
363363
}
364364

365-
cmd := strings.Join(asStringSlice(ps["Command"]), " ")
366-
if cmd != "" {
367-
out["command"] = cmd
365+
inspect := c.podmanInspect(ctx, name)
366+
367+
// Report the actual running command line as the config-false
368+
// "cmdline" leaf (an unrestricted string), built from inspect's
369+
// Path + Args like the legacy yanger collector. Do NOT report it
370+
// into the config-true "command" leaf: that leaf has a restrictive
371+
// pattern and a real command line (e.g. one containing "&&" or
372+
// quotes) fails YANG validation, which rejects the entire
373+
// containers subtree on read.
374+
if path := asString(inspect["Path"]); path != "" {
375+
parts := append([]string{path}, asStringSlice(inspect["Args"])...)
376+
out["cmdline"] = strings.Join(parts, " ")
368377
}
369378

370-
inspect := c.podmanInspect(ctx, name)
371379
if net := c.network(ps, inspect); len(net) > 0 {
372380
out["network"] = net
373381
}

src/yangerd/internal/collector/containers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestContainerBasicInfo(t *testing.T) {
6060
"Ports": []
6161
}
6262
]`),
63-
"podman inspect web": []byte(`[{}]`),
63+
"podman inspect web": []byte(`[{"Path":"nginx","Args":["-g","daemon off;"]}]`),
6464
"podman stats --no-stream --format json --no-reset web": []byte(`[]`),
6565
},
6666
Errors: map[string]error{},
@@ -87,8 +87,8 @@ func TestContainerBasicInfo(t *testing.T) {
8787
if c["status"] != "Up 2 hours" {
8888
t.Fatalf("status mismatch: %v", c["status"])
8989
}
90-
if c["command"] != "nginx -g daemon off;" {
91-
t.Fatalf("command mismatch: %v", c["command"])
90+
if c["cmdline"] != "nginx -g daemon off;" {
91+
t.Fatalf("cmdline mismatch: %v", c["cmdline"])
9292
}
9393
if c["running"] != true {
9494
t.Fatalf("running expected true, got %v", c["running"])

0 commit comments

Comments
 (0)