mirror of
https://github.com/containers/podman-compose.git
synced 2025-08-16 00:28:00 +02:00
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 <povilas@radix.lt>
This commit is contained in:
@ -61,6 +61,19 @@ network:
|
|||||||
- "10.1.2.4"
|
- "10.1.2.4"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* `x-podman.routes` - Specifies a list of additional routes for the network. This corresponds to
|
||||||
|
`--route` option in `podman network create`.
|
||||||
|
|
||||||
|
For example, the following docker-compose.yml blocks network connectivity to specified subnet from
|
||||||
|
all containers on the network:
|
||||||
|
```yml
|
||||||
|
version: "3"
|
||||||
|
network:
|
||||||
|
my_network:
|
||||||
|
x-podman.routes:
|
||||||
|
- "10.2.3.4,127.0.0.1"
|
||||||
|
```
|
||||||
|
|
||||||
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).
|
||||||
|
|
||||||
|
2
newsfragments/x-podman-network-routes.feature
Normal file
2
newsfragments/x-podman-network-routes.feature
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Added support to set `--route` option to `podman network create` via
|
||||||
|
`x-podman.routes` key on network configuration.
|
@ -898,6 +898,10 @@ def get_network_create_args(net_desc: dict[str, Any], proj_name: str, net_name:
|
|||||||
"--dns",
|
"--dns",
|
||||||
",".join(norm_as_list(net_desc.get("x-podman.dns"))),
|
",".join(norm_as_list(net_desc.get("x-podman.dns"))),
|
||||||
))
|
))
|
||||||
|
if net_desc.get("x-podman.routes"):
|
||||||
|
routes = norm_as_list(net_desc.get("x-podman.routes"))
|
||||||
|
for route in routes:
|
||||||
|
args.extend(["--route", route])
|
||||||
|
|
||||||
if isinstance(ipam_config_ls, dict):
|
if isinstance(ipam_config_ls, dict):
|
||||||
ipam_config_ls = [ipam_config_ls]
|
ipam_config_ls = [ipam_config_ls]
|
||||||
|
@ -237,3 +237,41 @@ 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_routes_string(self) -> None:
|
||||||
|
net_desc = self.get_minimal_net_desc()
|
||||||
|
net_desc["x-podman.routes"] = "192.168.1.0/24"
|
||||||
|
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}",
|
||||||
|
"--route",
|
||||||
|
"192.168.1.0/24",
|
||||||
|
net_name,
|
||||||
|
]
|
||||||
|
args = get_network_create_args(net_desc, proj_name, net_name)
|
||||||
|
self.assertEqual(args, expected_args)
|
||||||
|
|
||||||
|
def test_routes_list(self) -> None:
|
||||||
|
net_desc = self.get_minimal_net_desc()
|
||||||
|
net_desc["x-podman.routes"] = ["192.168.1.0/24", "192.168.2.0/24"]
|
||||||
|
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}",
|
||||||
|
"--route",
|
||||||
|
"192.168.1.0/24",
|
||||||
|
"--route",
|
||||||
|
"192.168.2.0/24",
|
||||||
|
net_name,
|
||||||
|
]
|
||||||
|
args = get_network_create_args(net_desc, proj_name, net_name)
|
||||||
|
self.assertEqual(args, expected_args)
|
||||||
|
Reference in New Issue
Block a user