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

podman: add --ulimit host #3491

Merged
merged 1 commit into from
Jul 11, 2019
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
2 changes: 2 additions & 0 deletions docs/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ The following example maps uids 0-2000 in the container to the uids 30000-31999

Ulimit options

You can pass `host` to copy the current configuration from the host.

**--user**, **-u**=*user*

Sets the username or UID used and optionally the groupname or GID for the specified command.
Expand Down
2 changes: 2 additions & 0 deletions docs/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ The example maps uids 0-2000 in the container to the uids 30000-31999 on the hos

Ulimit options

You can pass `host` to copy the current configuration from the host.

**--user**, **-u**=*user*

Sets the username or UID used and optionally the groupname or GID for the specified command.
Expand Down
20 changes: 20 additions & 0 deletions pkg/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import (

const cpuPeriod = 100000

type systemUlimit struct {
name string
max uint64
cur uint64
}

func getAvailableGids() (int64, error) {
idMap, err := user.ParseIDMapFile("/proc/self/gid_map")
if err != nil {
Expand Down Expand Up @@ -553,6 +559,20 @@ func addRlimits(config *CreateConfig, g *generate.Generator) error {
)

for _, u := range config.Resources.Ulimit {
if u == "host" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really no way to tell runc "just don't change rlimits"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems I've unnecessarily complicated things. Looks like it is enough to not specify any limits block and that won't change the rlimits. I'll do some more tests and open a PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much simpler version: #3583

if len(config.Resources.Ulimit) != 1 {
return errors.New("ulimit can use host only once")
}
hostLimits, err := getHostRlimits()
if err != nil {
return err
}
for _, i := range hostLimits {
g.AddProcessRlimits(i.name, i.max, i.cur)
}
break
}

ul, err := units.ParseUlimit(u)
if err != nil {
return errors.Wrapf(err, "ulimit option %q requires name=SOFT:HARD, failed to be parsed", u)
Expand Down
42 changes: 42 additions & 0 deletions pkg/spec/spec_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//+build linux

package createconfig

import (
"syscall"

"github.com/pkg/errors"
)

type systemRlimit struct {
name string
value int
}

var systemLimits = []systemRlimit{
{"RLIMIT_AS", syscall.RLIMIT_AS},
{"RLIMIT_CORE", syscall.RLIMIT_CORE},
{"RLIMIT_CPU", syscall.RLIMIT_CPU},
{"RLIMIT_DATA", syscall.RLIMIT_DATA},
{"RLIMIT_FSIZE", syscall.RLIMIT_FSIZE},
{"RLIMIT_NOFILE", syscall.RLIMIT_NOFILE},
{"RLIMIT_STACK", syscall.RLIMIT_STACK},
}

func getHostRlimits() ([]systemUlimit, error) {
ret := []systemUlimit{}
for _, i := range systemLimits {
var l syscall.Rlimit
if err := syscall.Getrlimit(i.value, &l); err != nil {
return nil, errors.Wrapf(err, "cannot read limits for %s", i.name)
}
s := systemUlimit{
name: i.name,
max: l.Max,
cur: l.Cur,
}
ret = append(ret, s)
}
return ret, nil

}
7 changes: 7 additions & 0 deletions pkg/spec/spec_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//+build !linux

package createconfig

func getHostRlimits() ([]systemUlimit, error) {
return nil, nil
}
21 changes: 21 additions & 0 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"net"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

. "github.com/containers/libpod/test/utils"
Expand Down Expand Up @@ -250,6 +252,25 @@ var _ = Describe("Podman run", func() {
Expect(session.OutputToString()).To(ContainSubstring("100"))
})

It("podman run limits host test", func() {
SkipIfRemote()

var l syscall.Rlimit

err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &l)
Expect(err).To(BeNil())

session := podmanTest.Podman([]string{"run", "--rm", "--ulimit", "host", fedoraMinimal, "ulimit", "-Hn"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

ulimitCtrStr := strings.TrimSpace(session.OutputToString())
ulimitCtr, err := strconv.ParseUint(ulimitCtrStr, 10, 0)
Expect(err).To(BeNil())

Expect(ulimitCtr).Should(BeNumerically(">=", l.Max))
})

It("podman run with cidfile", func() {
session := podmanTest.Podman([]string{"run", "--cidfile", tempdir + "cidfile", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expand Down