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

T6358: Container config option to enable host pid (backport #3472) #3476

Merged
merged 2 commits into from
May 17, 2024
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
8 changes: 7 additions & 1 deletion interface-definitions/container.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
<constraintErrorMessage>Container name must be alphanumeric and can contain hyphens</constraintErrorMessage>
</properties>
<children>
<leafNode name="allow-host-pid">
<properties>
<help>Allow sharing host process namespace with container</help>
<valueless/>
</properties>
</leafNode>
<leafNode name="allow-host-networks">
<properties>
<help>Allow host networks in container</help>
<help>Allow sharing host networking with container</help>
<valueless/>
</properties>
</leafNode>
Expand Down
1 change: 1 addition & 0 deletions smoketest/config-tests/container-simple
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ set container name c01 capability 'net-bind-service'
set container name c01 capability 'net-raw'
set container name c01 image 'busybox:stable'
set container name c02 allow-host-networks
set container name c02 allow-host-pid
set container name c02 capability 'sys-time'
set container name c02 image 'busybox:stable'
1 change: 1 addition & 0 deletions smoketest/configs/container-simple
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ container {
}
name c02 {
allow-host-networks
allow-host-pid
cap-add sys-time
image busybox:stable
}
Expand Down
11 changes: 5 additions & 6 deletions src/conf_mode/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,20 @@ def generate_run_arguments(name, container_config):
prop = vol_config['propagation']
volume += f' --volume {svol}:{dvol}:{mode},{prop}'

host_pid = ''
if 'allow_host_pid' in container_config:
host_pid = '--pid host'

container_base_cmd = f'--detach --interactive --tty --replace {capabilities} ' \
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \
f'--name {name} {hostname} {device} {port} {volume} {env_opt} {label} {uid}'
f'--name {name} {hostname} {device} {port} {volume} {env_opt} {label} {uid} {host_pid}'

entrypoint = ''
if 'entrypoint' in container_config:
# it needs to be json-formatted with single quote on the outside
entrypoint = json_write(container_config['entrypoint'].split()).replace('"', "&quot;")
entrypoint = f'--entrypoint &apos;{entrypoint}&apos;'

hostname = ''
if 'host_name' in container_config:
hostname = container_config['host_name']
hostname = f'--hostname {hostname}'

command = ''
if 'command' in container_config:
command = container_config['command'].strip()
Expand Down
Loading