From 09565285cfdc5db756414357af27e60487868c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 22 Jan 2024 20:56:08 +0100 Subject: [PATCH] Return RuntimeConfig with Linux.CgroupDriver --- core/docker_service.go | 20 ++++++++++++++++++++ core/docker_service_test.go | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/core/docker_service.go b/core/docker_service.go index 46c017d04..f35290b36 100644 --- a/core/docker_service.go +++ b/core/docker_service.go @@ -446,6 +446,26 @@ func (ds *dockerService) Status( return resp, nil } +// RuntimeConfig returns the config of the runtime. +func (ds *dockerService) RuntimeConfig( + _ context.Context, + r *runtimeapi.RuntimeConfigRequest, +) (*runtimeapi.RuntimeConfigResponse, error) { + resp := &runtimeapi.RuntimeConfigResponse{} + if runtime.GOOS == "linux" { + resp.Linux = &runtimeapi.LinuxRuntimeConfiguration{} + switch ds.cgroupDriver { + case "cgroupfs": + resp.Linux.CgroupDriver = runtimeapi.CgroupDriver_CGROUPFS + case "systemd": + resp.Linux.CgroupDriver = runtimeapi.CgroupDriver_SYSTEMD + default: + return nil, fmt.Errorf("unknown cgroup driver: %s", ds.cgroupDriver) + } + } + return resp, nil +} + func (ds *dockerService) ServeHTTP(w http.ResponseWriter, r *http.Request) { if ds.streamingServer != nil { ds.streamingServer.ServeHTTP(w, r) diff --git a/core/docker_service_test.go b/core/docker_service_test.go index a9804f036..542fed074 100644 --- a/core/docker_service_test.go +++ b/core/docker_service_test.go @@ -163,6 +163,14 @@ func TestStatus(t *testing.T) { }, statusResp.Status) } +// TestRuntimeConfig tests the runtime config logic. +func TestRuntimeConfig(t *testing.T) { + ds, fDocker, _ := newTestDockerService() + + configResp, err := ds.RuntimeConfig(getTestCTX(), &runtimeapi.RuntimeConfigRequest{}) + require.NoError(t, err) +} + func TestVersion(t *testing.T) { ds, _, _ := newTestDockerService()