Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEP-3619: Support RuntimeFeatures(.features) in "crictl info" command #1772

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/crictl/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ func Info(cliContext *cli.Context, client internalapi.RuntimeService) error {
return err
}

data := []statusData{{json: statusJSON, runtimeHandlers: string(handlers), info: r.Info}}
features, err := json.Marshal(r.Features) // protobufObjectToJSON cannot be used
if err != nil {
return err
}

data := []statusData{{json: statusJSON, runtimeHandlers: string(handlers), features: string(features), info: r.Info}}

return outputStatusData(data, cliContext.String("output"), cliContext.String("template"))
}
14 changes: 14 additions & 0 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func outputProtobufObjAsYAML(obj protoiface.MessageV1) error {
type statusData struct {
json string
runtimeHandlers string
features string
info map[string]string
}

Expand Down Expand Up @@ -360,6 +361,19 @@ func outputStatusData(statuses []statusData, format, tmplStr string) (err error)
}
}

if status.features != "" {
var featuresVal map[string]any = map[string]any{}

err := json.Unmarshal([]byte(status.features), &featuresVal)
if err != nil {
return fmt.Errorf("unmarshal features JSON: %w", err)
}

if featuresVal != nil {
infoMap["features"] = featuresVal
}
}

for _, k := range keys {
val := status.info[k]

Expand Down
18 changes: 16 additions & 2 deletions cmd/crictl/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ func TestOutputStatusData(t *testing.T) {
"name": "crun"
}
]`
featuresResponse = `{
"supplemental_groups_policy": true
}`
emptyResponse = ""
)

testCases := []struct {
name string
status string
handlers string
features string
info map[string]string
format string
tmplStr string
Expand All @@ -119,10 +123,11 @@ func TestOutputStatusData(t *testing.T) {
name: "YAML format",
status: statusResponse,
handlers: handlerResponse,
features: featuresResponse,
info: map[string]string{"key1": `{"foo": "bar"}`, "key2": `{"bar": "baz"}`},
format: outputTypeYAML,
tmplStr: "",
expectedOut: "key1:\n foo: bar\nkey2:\n bar: baz\nruntimeHandlers:\n- features:\n recursive_read_only_mounts: true\n name: runc\n- features:\n recursive_read_only_mounts: true\n user_namespaces: true\n name: crun\nstatus:\n conditions:\n - message: no network config found in C:\\Program Files\n reason: NetworkPluginNotReady\n status: false\n type: NetworkReady",
expectedOut: "features:\n supplemental_groups_policy: true\nkey1:\n foo: bar\nkey2:\n bar: baz\nruntimeHandlers:\n- features:\n recursive_read_only_mounts: true\n name: runc\n- features:\n recursive_read_only_mounts: true\n user_namespaces: true\n name: crun\nstatus:\n conditions:\n - message: no network config found in C:\\Program Files\n reason: NetworkPluginNotReady\n status: false\n type: NetworkReady",
},
{
name: "YAML format with empty status response",
Expand All @@ -140,6 +145,15 @@ func TestOutputStatusData(t *testing.T) {
tmplStr: "",
expectedOut: "status:\n conditions:\n - message: no network config found in C:\\Program Files\n reason: NetworkPluginNotReady\n status: false\n type: NetworkReady",
},
{
name: "YAML format with empty features response",
status: statusResponse,
handlers: handlerResponse,
features: emptyResponse,
format: outputTypeYAML,
tmplStr: "",
expectedOut: "runtimeHandlers:\n- features:\n recursive_read_only_mounts: true\n name: runc\n- features:\n recursive_read_only_mounts: true\n user_namespaces: true\n name: crun\nstatus:\n conditions:\n - message: no network config found in C:\\Program Files\n reason: NetworkPluginNotReady\n status: false\n type: NetworkReady",
},
{
name: "JSON format",
status: statusResponse,
Expand Down Expand Up @@ -188,7 +202,7 @@ func TestOutputStatusData(t *testing.T) {
}

outStr, err := captureOutput(func() error {
data := []statusData{{json: tc.status, runtimeHandlers: tc.handlers, info: tc.info}}
data := []statusData{{json: tc.status, runtimeHandlers: tc.handlers, features: tc.features, info: tc.info}}

err := outputStatusData(data, tc.format, tc.tmplStr)
if err != nil {
Expand Down
Loading