From ae6d3437dc3247c396444b7f65eb49a98b0dd800 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 2 Nov 2025 09:30:05 +0100 Subject: 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. --- python/vyos/container.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 python/vyos/container.py (limited to 'python') 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 +# +# 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 . + +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 -- cgit v1.2.3