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:
parent
89c72d74d7
commit
c6c3ae020d
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
docker: Fixed a bug where cgroups-v1 parent was being set
|
||||
```
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue