Skip to content

Commit

Permalink
T6927: adds option to set container name server
Browse files Browse the repository at this point in the history
  • Loading branch information
nvollmar committed Dec 5, 2024
1 parent 6dd7bef commit a09a769
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions interface-definitions/container.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
</properties>
<defaultValue>64</defaultValue>
</leafNode>
#include <include/name-server-ipv4-ipv6.xml.i>
<tagNode name="network">
<properties>
<help>Attach user defined network to container</help>
Expand Down
12 changes: 12 additions & 0 deletions smoketest/scripts/cli/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def test_basic(self):
tmp = cmd(f'sudo podman exec -it {cont_name} sysctl kernel.msgmax')
self.assertEqual(tmp, 'kernel.msgmax = 4096')

def test_name_server(self):
cont_name = 'dnstest'
name_server = '192.168.0.1'
self.cli_set(base_path + ['name', cont_name, 'image', cont_image])
self.cli_set(base_path + ['name', cont_name, 'allow-host-networks'])
self.cli_set(base_path + ['name', cont_name, 'name-server', name_server])

self.cli_commit()

n = cmd_to_json(f'sudo podman inspect {cont_name}')
self.assertEqual(n['HostConfig']['Dns'][0], name_server)

def test_cpu_limit(self):
cont_name = 'c2'

Expand Down
7 changes: 6 additions & 1 deletion src/conf_mode/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,14 @@ def generate_run_arguments(name, container_config):
if 'allow_host_pid' in container_config:
host_pid = '--pid host'

name_server = ''
if 'name_server' in container_config:
name_server = container_config['name_server']
name_server = f'--dns {name_server}'

container_base_cmd = f'--detach --interactive --tty --replace {capabilities} --cpus {cpu_quota} {sysctl_opt} ' \
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} {host_pid}'
f'--name {name} {hostname} {device} {port} {name_server} {volume} {env_opt} {label} {uid} {host_pid}'

entrypoint = ''
if 'entrypoint' in container_config:
Expand Down

0 comments on commit a09a769

Please sign in to comment.