From e1b6ae7c13c530ee1c358df5e32d4b23868b1e1b Mon Sep 17 00:00:00 2001 From: yatin Date: Fri, 6 Apr 2018 10:20:36 +0530 Subject: [PATCH] Add ulimit option for run action This will allow to set ulimit for a container. Change-Id: I0cfcf4e3e3e13578ec42e12f459732992fb3a760 Related-Bug: #1760471 (cherry picked from commit 9348078452965b54ef5337913ac602e4194b7796) --- paunch/builder/compose1.py | 3 +++ paunch/tests/test_builder_compose1.py | 2 ++ .../notes/add-ulimit-option-30dbd38044d26208.yaml | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 releasenotes/notes/add-ulimit-option-30dbd38044d26208.yaml diff --git a/paunch/builder/compose1.py b/paunch/builder/compose1.py index 9c75222..5472d37 100644 --- a/paunch/builder/compose1.py +++ b/paunch/builder/compose1.py @@ -158,6 +158,9 @@ class ComposeV1Builder(object): cmd.append('--pid=%s' % cconfig['pid']) if 'uts' in cconfig: cmd.append('--uts=%s' % cconfig['uts']) + for u in cconfig.get('ulimit', []): + if u: + cmd.append('--ulimit=%s' % u) if 'healthcheck' in cconfig: hconfig = cconfig['healthcheck'] if 'test' in hconfig: diff --git a/paunch/tests/test_builder_compose1.py b/paunch/tests/test_builder_compose1.py index faf8ab3..7f032c9 100644 --- a/paunch/tests/test_builder_compose1.py +++ b/paunch/tests/test_builder_compose1.py @@ -447,6 +447,7 @@ three-12345678 three''', '', 0), 'interactive': True, 'environment': ['FOO=BAR', 'BAR=BAZ'], 'env_file': ['/tmp/foo.env', '/tmp/bar.env'], + 'ulimit': ['nofile=1024', 'nproc=1024'], 'volumes': ['/foo:/foo:rw', '/bar:/bar:ro'], 'volumes_from': ['two', 'three'] } @@ -460,6 +461,7 @@ three-12345678 three''', '', 0), '--env-file=/tmp/foo.env', '--env-file=/tmp/bar.env', '--env=FOO=BAR', '--env=BAR=BAZ', '--rm', '--interactive', '--tty', + '--ulimit=nofile=1024', '--ulimit=nproc=1024', '--volume=/foo:/foo:rw', '--volume=/bar:/bar:ro', '--volumes-from=two', '--volumes-from=three', 'centos:7', 'ls', '-l', '/foo'], diff --git a/releasenotes/notes/add-ulimit-option-30dbd38044d26208.yaml b/releasenotes/notes/add-ulimit-option-30dbd38044d26208.yaml new file mode 100644 index 0000000..8123b54 --- /dev/null +++ b/releasenotes/notes/add-ulimit-option-30dbd38044d26208.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Add `--ulimit=xxx` option for paunch run action. Using + this option, multiple ulimits can be set for the container. + For example, `--ulimit=nproc=1024 --ulimit=nofile=1024` will + set proc and nofile limit to 1024 for the container. +