diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-11-02 09:30:05 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-11-03 21:09:14 +0100 |
| commit | ae6d3437dc3247c396444b7f65eb49a98b0dd800 (patch) | |
| tree | 79b3e008ad916e476c67eea1af327ddcfd67552c /python | |
| parent | f61656f9a0010498b1778c43a599862e84250b7d (diff) | |
| download | vyos-1x-ae6d3437dc3247c396444b7f65eb49a98b0dd800.tar.gz vyos-1x-ae6d3437dc3247c396444b7f65eb49a98b0dd800.zip | |
container: T7305: fix VRF loss when restarting pods
Container networks are only started when there is at least one active consumer.
If a network is created without any attached containers, it does not need to be
assigned to a VRF yet.
When the last container in a pod is stopped, its associated container network
is removed. Upon container restart, the kernel recreates the network, but the
VRF assignment may be lost in the process.
This change ensures that all container networks are correctly reattached to
their designated VRFs when a pod restarts.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/container.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/python/vyos/container.py b/python/vyos/container.py new file mode 100644 index 000000000..475d796f2 --- /dev/null +++ b/python/vyos/container.py @@ -0,0 +1,41 @@ +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from vyos.config import Config +from vyos.ifconfig import Interface +from vyos.utils.dict import dict_search +from vyos.utils.network import interface_exists + +def restart_network(config: Config) -> None: + """ + Start network and assign it to given VRF if requested. + + This can only be done after the containers got started as the podman network + interface will only be enabled by the first container and yet I do not know + how to enable the network interface in advance. + """ + if 'network' in config: + for network, network_config in config['network'].items(): + type_config = dict_search('type', network_config) + if not dict_search('macvlan', type_config): + network_name = f'pod-{network}' + # T5147: Networks are started only as soon as there is a consumer. + # If only a network is created in the first place, no need to assign + # it to a VRF as there's no consumer, yet. + if interface_exists(network_name): + tmp = Interface(network_name) + tmp.set_vrf(network_config.get('vrf', '')) + tmp.add_ipv6_eui64_address('fe80::/64') + + return None |
