Skip to content

Commit b7e9483

Browse files
authored
Merge pull request #5423 from indrajitr/container-cgroupns
T9240: container: Allow sharing host's cgroup namespace with container
2 parents e956c12 + 61068a7 commit b7e9483

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

interface-definitions/container.xml.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<valueless/>
2828
</properties>
2929
</leafNode>
30+
<leafNode name="allow-host-cgroups">
31+
<properties>
32+
<help>Allow sharing host cgroup namespace with container</help>
33+
<valueless/>
34+
</properties>
35+
</leafNode>
3036
<leafNode name="capability">
3137
<properties>
3238
<help>Grant individual Linux capability to container instance</help>

smoketest/scripts/cli/test_container.py

100755100644
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def test_basic(self):
8787
self.cli_set(base_path + ['name', cont_name, 'sysctl', 'parameter',
8888
'kernel.msgmax', 'value', '4096'])
8989
self.cli_set(base_path + ['name', cont_name, 'log-driver', 'journald'])
90+
self.cli_set(base_path + ['name', cont_name, 'allow-host-cgroups'])
9091
# commit changes
9192
self.cli_commit()
9293

@@ -104,6 +105,7 @@ def test_basic(self):
104105
l = cmd_to_json(['container', 'inspect', cont_name])
105106
self.assertEqual(l['HostConfig']['LogConfig']['Type'], 'journald')
106107
self.assertEqual(l['Config']['Healthcheck']['Test'], ['NONE'])
108+
self.assertEqual(l['HostConfig']['CgroupMode'], 'host')
107109

108110
def test_healthcheck(self):
109111
cont_name = 'health-test'

src/conf_mode/container.py

100755100644
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ def generate_run_arguments(name, container_config, host_ident, network_config):
475475
if 'allow_host_pid' in container_config:
476476
host_pid = '--pid host'
477477

478+
cgroupns = ''
479+
if 'allow_host_cgroups' in container_config:
480+
cgroupns = '--cgroupns host'
481+
478482
name_server = []
479483
if 'name_server' in container_config:
480484
for ns in container_config['name_server']:
@@ -486,7 +490,7 @@ def generate_run_arguments(name, container_config, host_ident, network_config):
486490

487491
container_base_cmd = f'--detach --interactive --tty --replace {capabilities} {privileged} --cpus {cpu_quota} {sysctl_opt} ' \
488492
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} --log-driver={log_driver} ' \
489-
f'--name {name} {hostname} {device} {port} {name_server} {volume} {tmpfs} {env_opt} {label} {uid} {host_pid}'
493+
f'--name {name} {hostname} {device} {port} {name_server} {volume} {tmpfs} {env_opt} {label} {uid} {host_pid} {cgroupns}'
490494

491495
entrypoint = ''
492496
if 'entrypoint' in container_config:

0 commit comments

Comments
 (0)