From a5f4306a3d2b2165b2af5845d0de808f92175f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 13 Apr 2023 14:30:07 +0200 Subject: [PATCH] Add basic crictl info config with sandboxImage --- core/docker_service.go | 20 +++++++++++++++++++- core/docker_service_test.go | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/docker_service.go b/core/docker_service.go index 52cfdf8c1..9fb1ad088 100644 --- a/core/docker_service.go +++ b/core/docker_service.go @@ -18,6 +18,7 @@ package core import ( "context" + "encoding/json" "fmt" "io" "net/http" @@ -395,7 +396,24 @@ func (ds *dockerService) Status( networkReady.Message = fmt.Sprintf("docker: network plugin is not ready: %v", err) } status := &runtimeapi.RuntimeStatus{Conditions: conditions} - return &runtimeapi.StatusResponse{Status: status}, nil + resp := &runtimeapi.StatusResponse{Status: status} + if r.Verbose { + image := defaultSandboxImage + podSandboxImage := ds.podSandboxImage + if len(podSandboxImage) != 0 { + image = podSandboxImage + } + config := map[string]interface{}{ + "sandboxImage": image, + } + configByt, err := json.Marshal(config) + if err != nil { + return nil, err + } + resp.Info = make(map[string]string) + resp.Info["config"] = string(configByt) + } + return resp, nil } func (ds *dockerService) ServeHTTP(w http.ResponseWriter, r *http.Request) { diff --git a/core/docker_service_test.go b/core/docker_service_test.go index a5178856a..beae9010f 100644 --- a/core/docker_service_test.go +++ b/core/docker_service_test.go @@ -149,6 +149,11 @@ func TestStatus(t *testing.T) { runtimeapi.NetworkReady: true, }, statusResp.Status) + // Should report info if verbose. + statusResp, err = ds.Status(getTestCTX(), &runtimeapi.StatusRequest{Verbose: true}) + require.NoError(t, err) + assert.NotNil(t, statusResp.Info) + // Should not report ready status is network plugin returns error. mockPlugin := newTestNetworkPlugin(t) ds.network = network.NewPluginManager(mockPlugin)