Skip to content

Commit

Permalink
Merge pull request #4218 from nvollmar/T6927
Browse files Browse the repository at this point in the history
T6927: adds option to set container name server
  • Loading branch information
c-po authored Dec 9, 2024
2 parents 6733ebc + 1db8a48 commit 3ed6f02
Show file tree
Hide file tree
Showing 3 changed files with 22 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
15 changes: 15 additions & 0 deletions smoketest/scripts/cli/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ 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 = 'dns-test'
name_server = '192.168.0.1'
self.cli_set(base_path + ['name', cont_name, 'allow-host-networks'])
self.cli_set(base_path + ['name', cont_name, 'image', cont_image])
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)

tmp = cmd(f'sudo podman exec -it {cont_name} cat /etc/resolv.conf')
self.assertIn(name_server, tmp)

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:
for ns in container_config['name_server']:
name_server += f'--dns {ns}'

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 3ed6f02

Please sign in to comment.