Skip to content

Commit

Permalink
Return RuntimeConfig with Linux.CgroupDriver - backport release/0.3 (
Browse files Browse the repository at this point in the history
…#425)

Co-authored-by: Nick Neisen <[email protected]>
  • Loading branch information
afbjorklund and nwneisen authored Jan 21, 2025
1 parent dee07c9 commit d3c4a89
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit d3c4a89

Please sign in to comment.