Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/13058.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
docker: Fixed a bug where cgroups-v1 parent was being set
```
14 changes: 10 additions & 4 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down