
runc considers libcontainer to be "unstable" (not for external use), so we try not to use it. Commited47d6ba76
brought back the dependency on other parts of libcontainer, but looks to be only depending on a single utility, which in itself was borrowed from github.com/coreos/go-systemd to not introduce CGO code in the same package. This patch copies the version from github.com/coreos/go-systemd (adding proper attribution, although the function is pretty trivial). runc is in process of moving the libcontainer/user package to an external module, which means we can remove the dependency on libcontainer entirely in the near future. There is one more use of `libcontainer` in our vendor tree; it looks like CDI is depending on one utility (devices.DeviceFromPath);a943033a8b/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/container-edits_unix.go (L38)
We should remove the dependency on that utility, and add a CI check to prevent bringing it back. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
106 lines
3.3 KiB
Go
106 lines
3.3 KiB
Go
/*
|
|
Copyright The containerd Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
criconfig "github.com/containerd/containerd/pkg/cri/config"
|
|
"github.com/containerd/containerd/pkg/systemd"
|
|
"github.com/containerd/containerd/plugin"
|
|
"github.com/stretchr/testify/assert"
|
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
|
)
|
|
|
|
func newFakeRuntimeConfig(runcV2, systemdCgroup bool) criconfig.Runtime {
|
|
r := criconfig.Runtime{Type: "default", Options: map[string]interface{}{}}
|
|
if runcV2 {
|
|
r.Type = plugin.RuntimeRuncV2
|
|
if systemdCgroup {
|
|
r.Options["SystemdCgroup"] = true
|
|
}
|
|
}
|
|
return r
|
|
}
|
|
|
|
func TestRuntimeConfig(t *testing.T) {
|
|
autoDetected := runtime.CgroupDriver_CGROUPFS
|
|
if systemd.IsRunningSystemd() {
|
|
autoDetected = runtime.CgroupDriver_SYSTEMD
|
|
}
|
|
|
|
for _, test := range []struct {
|
|
desc string
|
|
defaultRuntime string
|
|
runtimes map[string]criconfig.Runtime
|
|
expectedCgroupDriver runtime.CgroupDriver
|
|
}{
|
|
{
|
|
desc: "no runtimes",
|
|
expectedCgroupDriver: autoDetected,
|
|
},
|
|
{
|
|
desc: "non-runc runtime",
|
|
defaultRuntime: "non-runc",
|
|
runtimes: map[string]criconfig.Runtime{"non-runc": newFakeRuntimeConfig(false, false)},
|
|
expectedCgroupDriver: autoDetected,
|
|
},
|
|
{
|
|
desc: "no default, pick first in alphabetical order",
|
|
runtimes: map[string]criconfig.Runtime{
|
|
"non-runc": newFakeRuntimeConfig(false, false),
|
|
"runc-2": newFakeRuntimeConfig(true, true),
|
|
"runc": newFakeRuntimeConfig(true, false),
|
|
"non-runc-2": newFakeRuntimeConfig(false, false),
|
|
},
|
|
expectedCgroupDriver: runtime.CgroupDriver_CGROUPFS,
|
|
},
|
|
{
|
|
desc: "pick default, cgroupfs",
|
|
defaultRuntime: "runc-2",
|
|
runtimes: map[string]criconfig.Runtime{
|
|
"non-runc": newFakeRuntimeConfig(false, false),
|
|
"runc": newFakeRuntimeConfig(true, true),
|
|
"runc-2": newFakeRuntimeConfig(true, false),
|
|
},
|
|
expectedCgroupDriver: runtime.CgroupDriver_CGROUPFS,
|
|
},
|
|
{
|
|
desc: "pick default, systemd",
|
|
defaultRuntime: "runc-2",
|
|
runtimes: map[string]criconfig.Runtime{
|
|
"non-runc": newFakeRuntimeConfig(false, false),
|
|
"runc": newFakeRuntimeConfig(true, false),
|
|
"runc-2": newFakeRuntimeConfig(true, true),
|
|
},
|
|
expectedCgroupDriver: runtime.CgroupDriver_SYSTEMD,
|
|
},
|
|
} {
|
|
test := test
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
c := newTestCRIService()
|
|
c.config.PluginConfig.ContainerdConfig.DefaultRuntimeName = test.defaultRuntime
|
|
c.config.PluginConfig.ContainerdConfig.Runtimes = test.runtimes
|
|
|
|
resp, err := c.RuntimeConfig(context.TODO(), &runtime.RuntimeConfigRequest{})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, test.expectedCgroupDriver, resp.Linux.CgroupDriver, "got unexpected cgroup driver")
|
|
})
|
|
}
|
|
}
|