Skip to content

Commit

Permalink
Merge pull request containers#11567 from giuseppe/cgroups-split-with-…
Browse files Browse the repository at this point in the history
…pods

libpod: honor --cgroups=split also with pods
  • Loading branch information
openshift-merge-robot committed Sep 15, 2021
2 parents 81f41ca + 44abc17 commit c0cde37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
3 changes: 0 additions & 3 deletions libpod/container_internal_linux.go
Expand Up @@ -2490,9 +2490,6 @@ func (c *Container) getOCICgroupPath() (string, error) {
case c.config.NoCgroups:
return "", nil
case c.config.CgroupsMode == cgroupSplit:
if c.config.CgroupParent != "" {
return c.config.CgroupParent, nil
}
selfCgroup, err := utils.GetOwnCgroup()
if err != nil {
return "", err
Expand Down
53 changes: 32 additions & 21 deletions test/e2e/run_test.go
Expand Up @@ -1296,31 +1296,42 @@ USER mail`, BB)
SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users")
SkipIfRemote("--cgroups=split cannot be used in remote mode")

container := podmanTest.Podman([]string{"run", "--rm", "--cgroups=split", ALPINE, "cat", "/proc/self/cgroup"})
container.WaitWithDefaultTimeout()
Expect(container).Should(Exit(0))
lines := container.OutputToStringArray()

cgroup := ""
for _, line := range lines {
parts := strings.SplitN(line, ":", 3)
if !CGROUPSV2 {
// ignore unified on cgroup v1.
// both runc and crun do not set it.
// crun does not set named hierarchies.
if parts[1] == "" || strings.Contains(parts[1], "name=") {
checkLines := func(lines []string) {
cgroup := ""
for _, line := range lines {
parts := strings.SplitN(line, ":", 3)
if len(parts) < 2 {
continue
}
if !CGROUPSV2 {
// ignore unified on cgroup v1.
// both runc and crun do not set it.
// crun does not set named hierarchies.
if parts[1] == "" || strings.Contains(parts[1], "name=") {
continue
}
}
if parts[2] == "/" {
continue
}
if cgroup == "" {
cgroup = parts[2]
continue
}
Expect(cgroup).To(Equal(parts[2]))
}
if parts[2] == "/" {
continue
}
if cgroup == "" {
cgroup = parts[2]
continue
}
Expect(cgroup).To(Equal(parts[2]))
}

container := podmanTest.Podman([]string{"run", "--rm", "--cgroups=split", ALPINE, "cat", "/proc/self/cgroup"})
container.WaitWithDefaultTimeout()
Expect(container).Should(Exit(0))
checkLines(container.OutputToStringArray())

// check that --cgroups=split is honored also when a container runs in a pod
container = podmanTest.Podman([]string{"run", "--rm", "--pod", "new:split-test-pod", "--cgroups=split", ALPINE, "cat", "/proc/self/cgroup"})
container.WaitWithDefaultTimeout()
Expect(container).Should(Exit(0))
checkLines(container.OutputToStringArray())
})

It("podman run with cgroups=disabled runs without cgroups", func() {
Expand Down

0 comments on commit c0cde37

Please sign in to comment.