mirror of
https://github.com/containers/podman-compose.git
synced 2025-01-27 16:29:35 +01:00
Add network "dns" support
This patch add 'x-podman.dns' option to the 'network' configuration, allowing users to set the DNS resolvers for a defined network. Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
This commit is contained in:
parent
6e642dca1f
commit
9be3ec985f
@ -32,6 +32,18 @@ For explanations of these extensions, please refer to the [Podman Documentation]
|
|||||||
The following extension keys are available under network configuration:
|
The following extension keys are available under network configuration:
|
||||||
|
|
||||||
* `x-podman.disable-dns` - Disable the DNS plugin for the network when set to 'true'.
|
* `x-podman.disable-dns` - Disable the DNS plugin for the network when set to 'true'.
|
||||||
|
* `x-podman.dns` - Set nameservers for the network using supplied addresses (cannot be used with x-podman.disable-dns`).
|
||||||
|
|
||||||
|
For example, the following docker-compose.yml allows all containers on the same network to use the
|
||||||
|
specified nameservers:
|
||||||
|
```yml
|
||||||
|
version: "3"
|
||||||
|
network:
|
||||||
|
my_network:
|
||||||
|
x-podman.dns:
|
||||||
|
- "10.1.2.3"
|
||||||
|
- "10.1.2.4"
|
||||||
|
```
|
||||||
|
|
||||||
For explanations of these extensions, please refer to the
|
For explanations of these extensions, please refer to the
|
||||||
[Podman network create command Documentation](https://docs.podman.io/en/latest/markdown/podman-network-create.1.html).
|
[Podman network create command Documentation](https://docs.podman.io/en/latest/markdown/podman-network-create.1.html).
|
||||||
|
1
newsfragments/x-podman.dns.feature
Normal file
1
newsfragments/x-podman.dns.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
- Add support for 'x-podman.dns' to allow setting DNS nameservers for defined networks.
|
@ -835,6 +835,11 @@ def get_network_create_args(net_desc, proj_name, net_name):
|
|||||||
args.append("--ipv6")
|
args.append("--ipv6")
|
||||||
if net_desc.get("x-podman.disable_dns"):
|
if net_desc.get("x-podman.disable_dns"):
|
||||||
args.append("--disable-dns")
|
args.append("--disable-dns")
|
||||||
|
if net_desc.get("x-podman.dns"):
|
||||||
|
args.extend((
|
||||||
|
"--dns",
|
||||||
|
",".join(norm_as_list(net_desc.get("x-podman.dns"))),
|
||||||
|
))
|
||||||
|
|
||||||
if isinstance(ipam_config_ls, dict):
|
if isinstance(ipam_config_ls, dict):
|
||||||
ipam_config_ls = [ipam_config_ls]
|
ipam_config_ls = [ipam_config_ls]
|
||||||
|
@ -225,3 +225,53 @@ class TestGetNetworkCreateArgs(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
args = get_network_create_args(net_desc, proj_name, net_name)
|
args = get_network_create_args(net_desc, proj_name, net_name)
|
||||||
self.assertEqual(args, expected_args)
|
self.assertEqual(args, expected_args)
|
||||||
|
|
||||||
|
def test_dns_string(self):
|
||||||
|
net_desc = {
|
||||||
|
"labels": [],
|
||||||
|
"internal": False,
|
||||||
|
"driver": None,
|
||||||
|
"driver_opts": {},
|
||||||
|
"ipam": {"config": []},
|
||||||
|
"enable_ipv6": False,
|
||||||
|
"x-podman.dns": "192.168.1.2",
|
||||||
|
}
|
||||||
|
proj_name = "test_project"
|
||||||
|
net_name = "test_network"
|
||||||
|
expected_args = [
|
||||||
|
"create",
|
||||||
|
"--label",
|
||||||
|
f"io.podman.compose.project={proj_name}",
|
||||||
|
"--label",
|
||||||
|
f"com.docker.compose.project={proj_name}",
|
||||||
|
"--dns",
|
||||||
|
"192.168.1.2",
|
||||||
|
net_name,
|
||||||
|
]
|
||||||
|
args = get_network_create_args(net_desc, proj_name, net_name)
|
||||||
|
self.assertEqual(args, expected_args)
|
||||||
|
|
||||||
|
def test_dns_list(self):
|
||||||
|
net_desc = {
|
||||||
|
"labels": [],
|
||||||
|
"internal": False,
|
||||||
|
"driver": None,
|
||||||
|
"driver_opts": {},
|
||||||
|
"ipam": {"config": []},
|
||||||
|
"enable_ipv6": False,
|
||||||
|
"x-podman.dns": ["192.168.1.2", "192.168.1.3"],
|
||||||
|
}
|
||||||
|
proj_name = "test_project"
|
||||||
|
net_name = "test_network"
|
||||||
|
expected_args = [
|
||||||
|
"create",
|
||||||
|
"--label",
|
||||||
|
f"io.podman.compose.project={proj_name}",
|
||||||
|
"--label",
|
||||||
|
f"com.docker.compose.project={proj_name}",
|
||||||
|
"--dns",
|
||||||
|
"192.168.1.2,192.168.1.3",
|
||||||
|
net_name,
|
||||||
|
]
|
||||||
|
args = get_network_create_args(net_desc, proj_name, net_name)
|
||||||
|
self.assertEqual(args, expected_args)
|
||||||
|
Loading…
Reference in New Issue
Block a user