From e666587e61fb229c29058e6da7da4e7b6a67657d Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Mon, 12 Aug 2024 10:15:39 +0200 Subject: [PATCH] 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 (cherry picked from commit 793c3e08c303c5bc6ca4f9254c3e1f1ae8b25d7e) --- cmd/crictl/util.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/crictl/util.go b/cmd/crictl/util.go index 18f15febd0..0e04e10154 100644 --- a/cmd/crictl/util.go +++ b/cmd/crictl/util.go @@ -330,11 +330,19 @@ func outputStatusData(statuses []statusData, format, tmplStr string) (err error) } for _, k := range keys { - var genericVal map[string]any - if err := json.Unmarshal([]byte(status.info[k]), &genericVal); err != nil { - return fmt.Errorf("unmarshal status info JSON: %w", err) + val := status.info[k] + + if strings.HasPrefix(val, "{") { + // Assume a JSON object + var genericVal map[string]any + if err := json.Unmarshal([]byte(val), &genericVal); err != nil { + return fmt.Errorf("unmarshal status info JSON: %w", err) + } + infoMap[k] = genericVal + } else { + // Assume a string and remove any double quotes + infoMap[k] = strings.Trim(val, `"`) } - infoMap[k] = genericVal } result = append(result, infoMap)