diff --git a/paunch/builder/compose1.py b/paunch/builder/compose1.py index d8e72a3..e26ac45 100644 --- a/paunch/builder/compose1.py +++ b/paunch/builder/compose1.py @@ -62,6 +62,9 @@ class ComposeV1Builder(base.BaseBuilder): if 'log_tag' in cconfig: cmd.append('--log-opt=tag=%s' % cconfig['log_tag']) self.string_arg(cconfig, cmd, 'cpu_shares', '--cpu-shares') + self.string_arg(cconfig, cmd, 'mem_limit', '--memory') + self.string_arg(cconfig, cmd, 'memswap_limit', '--memory-swap') + self.string_arg(cconfig, cmd, 'mem_swappiness', '--memory-swappiness') self.string_arg(cconfig, cmd, 'security_opt', '--security-opt') self.string_arg(cconfig, cmd, 'stop_signal', '--stop-signal') @@ -88,9 +91,8 @@ class ComposeV1Builder(base.BaseBuilder): # domainname # hostname # mac_address - # mem_limit - # memswap_limit - # mem_swappiness + # memory_reservation + # kernel_memory # read_only # shm_size # stdin_open diff --git a/paunch/builder/podman.py b/paunch/builder/podman.py index 7a5368a..fb3bf5c 100644 --- a/paunch/builder/podman.py +++ b/paunch/builder/podman.py @@ -51,6 +51,9 @@ class PodmanBuilder(base.BaseBuilder): if 'log_tag' in cconfig: cmd.append('--log-opt=tag=%s' % cconfig['log_tag']) self.string_arg(cconfig, cmd, 'cpu_shares', '--cpu-shares') + self.string_arg(cconfig, cmd, 'mem_limit', '--memory') + self.string_arg(cconfig, cmd, 'memswap_limit', '--memory-swap') + self.string_arg(cconfig, cmd, 'mem_swappiness', '--memory-swappiness') self.string_arg(cconfig, cmd, 'security_opt', '--security-opt') self.string_arg(cconfig, cmd, 'stop_signal', '--stop-signal') diff --git a/paunch/tests/test_builder_compose1.py b/paunch/tests/test_builder_compose1.py index ec20394..c470712 100644 --- a/paunch/tests/test_builder_compose1.py +++ b/paunch/tests/test_builder_compose1.py @@ -37,6 +37,9 @@ class TestComposeV1Builder(tbb.TestBaseBuilder): 'env_file': '/tmp/foo.env', 'log_tag': '{{.ImageName}}/{{.Name}}/{{.ID}}', 'cpu_shares': 600, + 'mem_limit': '1G', + 'memswap_limit': '1G', + 'mem_swappiness': '60', 'security_opt': 'label:disable', 'cap_add': ['SYS_ADMIN', 'SETUID'], 'cap_drop': ['NET_RAW'] @@ -55,6 +58,9 @@ class TestComposeV1Builder(tbb.TestBaseBuilder): '--privileged=true', '--restart=always', '--user=bar', '--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}', '--cpu-shares=600', + '--memory=1G', + '--memory-swap=1G', + '--memory-swappiness=60', '--security-opt=label:disable', '--cap-add=SYS_ADMIN', '--cap-add=SETUID', '--cap-drop=NET_RAW', 'centos:7'], diff --git a/paunch/tests/test_builder_podman.py b/paunch/tests/test_builder_podman.py index 0df61fb..1855744 100644 --- a/paunch/tests/test_builder_podman.py +++ b/paunch/tests/test_builder_podman.py @@ -31,6 +31,9 @@ class TestPodmanBuilder(base.TestBaseBuilder): 'env_file': '/tmp/foo.env', 'log_tag': '{{.ImageName}}/{{.Name}}/{{.ID}}', 'cpu_shares': 600, + 'mem_limit': '1G', + 'memswap_limit': '1G', + 'mem_swappiness': '60', 'security_opt': 'label:disable', 'cap_add': ['SYS_ADMIN', 'SETUID'], 'cap_drop': ['NET_RAW'] @@ -47,6 +50,9 @@ class TestPodmanBuilder(base.TestBaseBuilder): '--uts=host', '--privileged=true', '--user=bar', '--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}', '--cpu-shares=600', + '--memory=1G', + '--memory-swap=1G', + '--memory-swappiness=60', '--security-opt=label:disable', '--cap-add=SYS_ADMIN', '--cap-add=SETUID', '--cap-drop=NET_RAW', 'centos:7'], diff --git a/releasenotes/notes/cgroups-memory-limit-ca571375d8047425.yaml b/releasenotes/notes/cgroups-memory-limit-ca571375d8047425.yaml new file mode 100644 index 0000000..5bb040a --- /dev/null +++ b/releasenotes/notes/cgroups-memory-limit-ca571375d8047425.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Add `--memory=x` option for the action run a container. This allows + setting constraints on max memory usage, which is `memory.limit_in_bytes` + in memory cgroup. + Also added `--memory-swap` and `--memory-swappiness` options to control + swap settings.