From 737387b156829e4076e1607b874ce2601965577e Mon Sep 17 00:00:00 2001 From: bobz965 Date: Fri, 18 Aug 2023 12:40:39 +0800 Subject: [PATCH] fix dpdk ovs rolling update Signed-off-by: bobz965 --- dist/images/start-ovs-dpdk-v2.sh | 18 +++++++++++++++--- dist/images/start-ovs-dpdk.sh | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dist/images/start-ovs-dpdk-v2.sh b/dist/images/start-ovs-dpdk-v2.sh index 0dd6ddc0b13..715ae412f71 100755 --- a/dist/images/start-ovs-dpdk-v2.sh +++ b/dist/images/start-ovs-dpdk-v2.sh @@ -27,9 +27,21 @@ export PATH=$PATH:/usr/share/openvswitch/scripts export PATH=$PATH:/usr/share/ovn/scripts function quit { - ovs-ctl stop - ovn-ctl stop_controller - exit 0 + gen_name=$(kubectl -n "${POD_NAMESPACE}" get pod "${POD_NAME}" -o jsonpath='{.metadata.generateName}') + revision_hash=$(kubectl -n "${POD_NAMESPACE}" get pod "${POD_NAME}" -o jsonpath='{.metadata.labels.controller-revision-hash}') + revision=$(kubectl -n "${POD_NAMESPACE}" get controllerrevision "${gen_name}${revision_hash}" -o jsonpath='{.revision}') + ds_name=${gen_name%-} + latest_revision=$(kubectl -n kube-system get controllerrevision --no-headers | awk '$2 == "daemonset.apps/'$ds_name'" {print $3}' | sort -nr | head -n1) + if [ "x$latest_revision" = "x$revision" ]; then + # stop ovn-controller/ovs only when the processes are in the same cgroup + pid=$(/usr/share/ovn/scripts/ovn-ctl status_controller | awk '{print $NF}') + if cgroup_match "${pid}" self; then + /usr/share/ovn/scripts/grace_stop_ovn_controller + /usr/share/openvswitch/scripts/ovs-ctl stop + fi + fi + + exit 0 } trap quit EXIT diff --git a/dist/images/start-ovs-dpdk.sh b/dist/images/start-ovs-dpdk.sh index dbed8a1f10b..f967174e489 100755 --- a/dist/images/start-ovs-dpdk.sh +++ b/dist/images/start-ovs-dpdk.sh @@ -2,9 +2,21 @@ set -euo pipefail function quit { - ovs-ctl stop - ovn-ctl stop_controller - exit 0 + gen_name=$(kubectl -n "${POD_NAMESPACE}" get pod "${POD_NAME}" -o jsonpath='{.metadata.generateName}') + revision_hash=$(kubectl -n "${POD_NAMESPACE}" get pod "${POD_NAME}" -o jsonpath='{.metadata.labels.controller-revision-hash}') + revision=$(kubectl -n "${POD_NAMESPACE}" get controllerrevision "${gen_name}${revision_hash}" -o jsonpath='{.revision}') + ds_name=${gen_name%-} + latest_revision=$(kubectl -n kube-system get controllerrevision --no-headers | awk '$2 == "daemonset.apps/'$ds_name'" {print $3}' | sort -nr | head -n1) + if [ "x$latest_revision" = "x$revision" ]; then + # stop ovn-controller/ovs only when the processes are in the same cgroup + pid=$(/usr/share/ovn/scripts/ovn-ctl status_controller | awk '{print $NF}') + if cgroup_match "${pid}" self; then + /usr/share/ovn/scripts/grace_stop_ovn_controller + /usr/share/openvswitch/scripts/ovs-ctl stop + fi + fi + + exit 0 } trap quit EXIT