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

Return RuntimeConfig with Linux.CgroupDriver - backport release/0.3 #425

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
20 changes: 20 additions & 0 deletions core/docker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions core/docker_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package core
import (
"errors"
"math/rand"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -163,6 +164,18 @@ func TestStatus(t *testing.T) {
}, statusResp.Status)
}

// TestRuntimeConfig tests the runtime config logic.
func TestRuntimeConfig(t *testing.T) {
ds, _, _ := newTestDockerService()
ds.cgroupDriver = "systemd"

configResp, err := ds.RuntimeConfig(getTestCTX(), &runtimeapi.RuntimeConfigRequest{})
require.NoError(t, err)
if runtime.GOOS == "linux" {
assert.Equal(t, runtimeapi.CgroupDriver_SYSTEMD, configResp.Linux.CgroupDriver)
}
}

func TestVersion(t *testing.T) {
ds, _, _ := newTestDockerService()

Expand Down
Loading