Skip to content

Commit

Permalink
Runtime config cgroup driver (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted authored Apr 2, 2024
2 parents 1ee226c + 680cec4 commit c62fa1b
Show file tree
Hide file tree
Showing 7 changed files with 1,629 additions and 493 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
k8s.io/client-go v0.27.8
k8s.io/component-base v0.27.8
k8s.io/component-helpers v0.27.8
k8s.io/cri-api v0.27.8
k8s.io/cri-api v0.28.0
k8s.io/cri-api/v1alpha2 v0.25.8
k8s.io/kubernetes v1.27.8
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
Expand Down Expand Up @@ -162,7 +162,7 @@ replace (
k8s.io/component-base => k8s.io/component-base v0.27.8
k8s.io/component-helpers => k8s.io/component-helpers v0.26.0
k8s.io/controller-manager => k8s.io/controller-manager v0.27.8
k8s.io/cri-api => k8s.io/cri-api v0.27.8
k8s.io/cri-api => k8s.io/cri-api v0.28.0
k8s.io/cri-api/v1alpha2 => k8s.io/cri-api v0.25.16
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.27.8
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.27.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,8 @@ k8s.io/component-helpers v0.26.0 h1:KNgwqs3EUdK0HLfW4GhnbD+q/Zl9U021VfIU7qoVYFk=
k8s.io/component-helpers v0.26.0/go.mod h1:jHN01qS/Jdj95WCbTe9S2VZ9yxpxXNY488WjF+yW4fo=
k8s.io/cri-api v0.25.16 h1:NSa4jRRP8zvEKBVfnWvMEaemvAsMXw5UQkLPQCRa2cc=
k8s.io/cri-api v0.25.16/go.mod h1:0vfZsZhEs3LoY5Lqm6Zgx43M633ToNlTUtEQc+VvXhw=
k8s.io/cri-api v0.27.8 h1:ptTyisTm3Zte5GMKjYVJNFlFRsuXlLCXCMY++JMLp8Q=
k8s.io/cri-api v0.27.8/go.mod h1:/YDseKYD84iAVzkaYWA4BNU/aCZVsb+1D9CsbTJnZ+4=
k8s.io/cri-api v0.28.0 h1:TVidtHNi425IaKF50oDD5hRvQuK7wB4NQAfTVOcr9QA=
k8s.io/cri-api v0.28.0/go.mod h1:xXygwvSOGcT/2KXg8sMYTHns2xFem3949kCQn5IS1k4=
k8s.io/csi-translation-lib v0.27.8 h1:oDfAN4NAuSLcd0QQzoRU9t8sIL0jmJrwcUKSf08rYGA=
k8s.io/csi-translation-lib v0.27.8/go.mod h1:759hl1fQE4QzFYipmhaQoVqPTodUZH+w6/F2788G1Jo=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand Down
Loading

0 comments on commit c62fa1b

Please sign in to comment.