Skip to content

Commit

Permalink
Merge pull request #13058 from hashicorp/b-cgroupsv1-docker-cgparent
Browse files Browse the repository at this point in the history
drivers/docker: do not set cgroup parent in v1 mode
  • Loading branch information
shoenig committed May 24, 2022
2 parents b181919 + 410834b commit 94abe33
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
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

0 comments on commit 94abe33

Please sign in to comment.