Skip to content

Commit

Permalink
Fix crictl info for containerd
Browse files Browse the repository at this point in the history
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 <sgrunert@redhat.com>
(cherry picked from commit 793c3e0)
  • Loading branch information
saschagrunert committed Aug 13, 2024
1 parent 5c35c71 commit e666587
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e666587

Please # to comment.