Skip to content

Commit 3e89041

Browse files
tonistiigiTibor Vass
authored andcommitted
Add ulimit support to libcontainerd addprocess
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> (cherry picked from commit 8891afd)
1 parent 1987d6e commit 3e89041

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

integration-cli/docker_cli_exec_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
485485
dockerCmd(c, "exec", "parent", "true")
486486
}
487487

488+
func (s *DockerSuite) TestExecUlimits(c *check.C) {
489+
testRequires(c, DaemonIsLinux)
490+
name := "testexeculimits"
491+
runSleepingContainer(c, "-d", "--ulimit", "nproc=21", "--name", name)
492+
c.Assert(waitRun(name), checker.IsNil)
493+
494+
out, _, err := dockerCmdWithError("exec", name, "sh", "-c", "ulimit -p")
495+
c.Assert(err, checker.IsNil)
496+
c.Assert(strings.TrimSpace(out), checker.Equals, "21")
497+
}
498+
488499
// #15750
489500
func (s *DockerSuite) TestExecStartFails(c *check.C) {
490501
// TODO Windows CI. This test should be portable. Figure out why it fails

libcontainerd/client_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (clnt *client) AddProcess(containerID, processFriendlyName string, specp Pr
7979
ApparmorProfile: sp.ApparmorProfile,
8080
SelinuxLabel: sp.SelinuxLabel,
8181
NoNewPrivileges: sp.NoNewPrivileges,
82+
Rlimits: convertRlimits(sp.Rlimits),
8283
}
8384

8485
iopipe, err := p.openFifos(sp.Terminal)

libcontainerd/utils_linux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ func systemPid(ctr *containerd.Container) uint32 {
3939
}
4040
return pid
4141
}
42+
43+
func convertRlimits(sr []specs.Rlimit) (cr []*containerd.Rlimit) {
44+
for _, r := range sr {
45+
cr = append(cr, &containerd.Rlimit{
46+
Type: r.Type,
47+
Hard: r.Hard,
48+
Soft: r.Soft,
49+
})
50+
}
51+
return
52+
}

0 commit comments

Comments
 (0)