Skip to content

Commit 793c3e0

Browse files
committed
Fix crictl info for containerd
We cannot just assume JSON objects because containerd will also return something like: ``` "golang": "go1.22.5", "lastCNILoadStatus": "OK", "lastCNILoadStatus.default": "OK", ``` For those values we just assume strings and prevent printing multiple double quotes to restore the v1.30.0 behavior of `crictl`. Signed-off-by: Sascha Grunert <[email protected]>
1 parent aa4e033 commit 793c3e0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: cmd/crictl/util.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,19 @@ func outputStatusData(statuses []statusData, format, tmplStr string) (err error)
330330
}
331331

332332
for _, k := range keys {
333-
var genericVal map[string]any
334-
if err := json.Unmarshal([]byte(status.info[k]), &genericVal); err != nil {
335-
return fmt.Errorf("unmarshal status info JSON: %w", err)
333+
val := status.info[k]
334+
335+
if strings.HasPrefix(val, "{") {
336+
// Assume a JSON object
337+
var genericVal map[string]any
338+
if err := json.Unmarshal([]byte(val), &genericVal); err != nil {
339+
return fmt.Errorf("unmarshal status info JSON: %w", err)
340+
}
341+
infoMap[k] = genericVal
342+
} else {
343+
// Assume a string and remove any double quotes
344+
infoMap[k] = strings.Trim(val, `"`)
336345
}
337-
infoMap[k] = genericVal
338346
}
339347

340348
result = append(result, infoMap)

0 commit comments

Comments
 (0)