drivers/docker: do not set cgroup parent in v1 mode

This PR fixes a bug where the CgroupParent on the docker
HostConfig struct was accidently being set when running in
cgroups v1 mode.
This commit is contained in:
Seth Hoenig 2022-05-17 15:11:57 -05:00
parent 89c72d74d7
commit c6c3ae020d
3 changed files with 39 additions and 4 deletions

3
.changelog/13058.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
docker: Fixed a bug where cgroups-v1 parent was being set
```

View File

@ -778,6 +778,15 @@ func memoryLimits(driverHardLimitMB int64, taskMemory drivers.MemoryResources) (
return hard * 1024 * 1024, softBytes
}
// Extract the cgroup parent from the nomad cgroup (only for linux/v2)
func cgroupParent(resources *drivers.Resources) string {
var parent string
if cgutil.UseV2 && resources != nil && resources.LinuxResources != nil {
parent, _ = cgutil.SplitPath(resources.LinuxResources.CpusetCgroupPath)
}
return parent
}
func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *TaskConfig,
imageID string) (docker.CreateContainerOptions, error) {
@ -843,11 +852,8 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
pidsLimit = driverConfig.PidsLimit
}
// Extract the cgroup parent from the nomad cgroup (bypass the need for plugin config)
parent, _ := cgutil.SplitPath(task.Resources.LinuxResources.CpusetCgroupPath)
hostConfig := &docker.HostConfig{
CgroupParent: parent,
CgroupParent: cgroupParent(task.Resources), // if applicable
Memory: memory, // hard limit
MemoryReservation: memoryReservation, // soft limit

View File

@ -2844,6 +2844,32 @@ func TestDockerDriver_memoryLimits(t *testing.T) {
}
}
func TestDockerDriver_cgroupParent(t *testing.T) {
ci.Parallel(t)
t.Run("v1", func(t *testing.T) {
testutil.CgroupsCompatibleV1(t)
parent := cgroupParent(&drivers.Resources{
LinuxResources: &drivers.LinuxResources{
CpusetCgroupPath: "/sys/fs/cgroup/cpuset/nomad",
},
})
require.Equal(t, "", parent)
})
t.Run("v2", func(t *testing.T) {
testutil.CgroupsCompatibleV2(t)
parent := cgroupParent(&drivers.Resources{
LinuxResources: &drivers.LinuxResources{
CpusetCgroupPath: "/sys/fs/cgroup/nomad.slice",
},
})
require.Equal(t, "nomad.slice", parent)
})
}
func TestDockerDriver_parseSignal(t *testing.T) {
ci.Parallel(t)