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

Add support for disable_dns, dns and ignore on network creation #1104

Merged
merged 2 commits into from
Jan 19, 2025
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
20 changes: 20 additions & 0 deletions docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ services:

For explanations of these extensions, please refer to the [Podman Documentation](https://docs.podman.io/).

## Network management

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.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
[Podman network create command Documentation](https://docs.podman.io/en/latest/markdown/podman-network-create.1.html).

## Per-network MAC-addresses

Expand Down
1 change: 1 addition & 0 deletions newsfragments/x-podman.disable-dns.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for 'x-podman.disable-dns' to allow disabling DNS plugin on defined networks.
1 change: 1 addition & 0 deletions newsfragments/x-podman.dns.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for 'x-podman.dns' to allow setting DNS nameservers for defined networks.
7 changes: 7 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,13 @@ def get_network_create_args(net_desc, proj_name, net_name):
ipam_config_ls = ipam.get("config", [])
if net_desc.get("enable_ipv6"):
args.append("--ipv6")
if net_desc.get("x-podman.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):
ipam_config_ls = [ipam_config_ls]
Expand Down
74 changes: 74 additions & 0 deletions tests/unit/test_get_network_create_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,77 @@ def test_complete(self):
]
args = get_network_create_args(net_desc, proj_name, net_name)
self.assertEqual(args, expected_args)

def test_disable_dns(self):
net_desc = {
"labels": [],
"internal": False,
"driver": None,
"driver_opts": {},
"ipam": {"config": []},
"enable_ipv6": False,
"x-podman.disable_dns": True,
}
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}",
"--disable-dns",
net_name,
]
args = get_network_create_args(net_desc, proj_name, net_name)
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