From 1dcbea52b92e656835b41441c4fb1acf3d7c1446 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 3 Apr 2024 09:42:46 +0200 Subject: [PATCH] confd: handle ip/route additions to container networks at runtime On any change to a container network interface we should schedule a restart of the container to activate the changes. This code triggers also at boot, when applying the whole startup-config, which initctl handles by queuing any create/touch events for services. This patch depends on the two previous commtis backporing fixes to Finit's initctl tool and an upgrade of the k8s-logger. Fixes #375 Signed-off-by: Joachim Wiberg --- board/common/rootfs/usr/sbin/container | 36 +++++++++++++++++++++++--- src/confd/src/cni.c | 11 ++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/board/common/rootfs/usr/sbin/container b/board/common/rootfs/usr/sbin/container index 67a80357..920aa6ba 100755 --- a/board/common/rootfs/usr/sbin/container +++ b/board/common/rootfs/usr/sbin/container @@ -217,6 +217,20 @@ netwrm() done } +# Schedule restart of (any) container using network $1 to activate network changes +netrestart() +{ + net=$1 + + for c in $(podman ps $all --format "{{.Names}}"); do + for n in $(podman inspect "$c" |jq -r '.[].NetworkSettings.Networks | keys[]'); do + if [ "$n" = "$net" ]; then + initctl -nbq touch "container@$c" + fi + done + done +} + usage() { cat <