Skip to content

Commit 8113a16

Browse files
committed
Add support to set --route of podman network create
This is not present in the compose spec. However, netavark podman network backend does support --route option, which is useful for various kinds of things. It is very easy to expose it. Signed-off-by: Povilas Kanapickas <[email protected]>
1 parent c7bce31 commit 8113a16

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

docs/Extensions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ network:
6161
- "10.1.2.4"
6262
```
6363

64+
* `x-podman.routes` - Specifies a list of additional routes for the network. This corresponds to
65+
`--route` option in `podman network create`.
66+
67+
For example, the following docker-compose.yml blocks network connectivity to specified subnet from
68+
all containers on the network:
69+
```yml
70+
version: "3"
71+
network:
72+
my_network:
73+
x-podman.routes:
74+
- "10.2.3.4,127.0.0.1"
75+
```
76+
6477
For explanations of these extensions, please refer to the
6578
[Podman network create command Documentation](https://docs.podman.io/en/latest/markdown/podman-network-create.1.html).
6679

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added support to set `--route` option to `podman network create` via
2+
`x-podman.routes` key on network configuration.

podman_compose.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ def get_network_create_args(net_desc: dict[str, Any], proj_name: str, net_name:
898898
"--dns",
899899
",".join(norm_as_list(net_desc.get("x-podman.dns"))),
900900
))
901+
if net_desc.get("x-podman.routes"):
902+
routes = norm_as_list(net_desc.get("x-podman.routes"))
903+
for route in routes:
904+
args.extend(["--route", route])
901905

902906
if isinstance(ipam_config_ls, dict):
903907
ipam_config_ls = [ipam_config_ls]

tests/unit/test_get_network_create_args.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,41 @@ def test_dns_list(self) -> None:
237237
]
238238
args = get_network_create_args(net_desc, proj_name, net_name)
239239
self.assertEqual(args, expected_args)
240+
241+
def test_routes_string(self) -> None:
242+
net_desc = self.get_minimal_net_desc()
243+
net_desc["x-podman.routes"] = "192.168.1.0/24"
244+
proj_name = "test_project"
245+
net_name = "test_network"
246+
expected_args = [
247+
"create",
248+
"--label",
249+
f"io.podman.compose.project={proj_name}",
250+
"--label",
251+
f"com.docker.compose.project={proj_name}",
252+
"--route",
253+
"192.168.1.0/24",
254+
net_name,
255+
]
256+
args = get_network_create_args(net_desc, proj_name, net_name)
257+
self.assertEqual(args, expected_args)
258+
259+
def test_routes_list(self) -> None:
260+
net_desc = self.get_minimal_net_desc()
261+
net_desc["x-podman.routes"] = ["192.168.1.0/24", "192.168.2.0/24"]
262+
proj_name = "test_project"
263+
net_name = "test_network"
264+
expected_args = [
265+
"create",
266+
"--label",
267+
f"io.podman.compose.project={proj_name}",
268+
"--label",
269+
f"com.docker.compose.project={proj_name}",
270+
"--route",
271+
"192.168.1.0/24",
272+
"--route",
273+
"192.168.2.0/24",
274+
net_name,
275+
]
276+
args = get_network_create_args(net_desc, proj_name, net_name)
277+
self.assertEqual(args, expected_args)

0 commit comments

Comments
 (0)