Skip to content

Commit

Permalink
Fix cgroup mode handling in api server
Browse files Browse the repository at this point in the history
Also change code to globably be consistent when refering to capatilized
Cgroup.

Fixed: #12550

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jan 14, 2022
1 parent a15dfb3 commit 607cb80
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/specgen/generate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
}

if s.CgroupsMode == "" {
s.CgroupsMode = rtc.Cgroups()
}

// If caller did not specify Pids Limits load default
if s.ResourceLimits == nil || s.ResourceLimits.Pids == nil {
if s.CgroupsMode != "disabled" {
Expand Down
9 changes: 9 additions & 0 deletions pkg/specgenutil/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/manifest"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/libpod/define"
Expand Down Expand Up @@ -490,6 +491,14 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
}
s.CgroupParent = c.CgroupParent
s.CgroupsMode = c.CgroupsMode
if s.CgroupsMode == "" {
rtc, err := config.Default()
if err != nil {
return err
}

s.CgroupsMode = rtc.Cgroups()
}

s.Groups = c.GroupAdd

Expand Down
31 changes: 31 additions & 0 deletions test/e2e/containers_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,35 @@ var _ = Describe("Podman run", func() {
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring(errorString))
})

It("podman containers.conf cgroups=disabled", func() {
if !strings.Contains(podmanTest.OCIRuntime, "crun") {
Skip("FIXME: requires crun")
}
conffile := filepath.Join(podmanTest.TempDir, "container.conf")

err := ioutil.WriteFile(conffile, []byte("[containers]\ncgroups=\"disabled\"\n"), 0755)
Expect(err).To(BeNil())

result := podmanTest.Podman([]string{"create", ALPINE, "true"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))

inspect := podmanTest.Podman([]string{"inspect", "--format", "{{ .HostConfig.Cgroups }}", result.OutputToString()})
inspect.WaitWithDefaultTimeout()
Expect(inspect.OutputToString()).To(Not(Equal("disabled")))

os.Setenv("CONTAINERS_CONF", conffile)
if IsRemote() {
podmanTest.RestartRemoteService()
}
result = podmanTest.Podman([]string{"create", ALPINE, "true"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))

inspect = podmanTest.Podman([]string{"inspect", "--format", "{{ .HostConfig.Cgroups }}", result.OutputToString()})
inspect.WaitWithDefaultTimeout()
Expect(inspect.OutputToString()).To(Equal("disabled"))
})

})

0 comments on commit 607cb80

Please sign in to comment.