From b76240f1dfa11612c14ddae825cf13f454317540 Mon Sep 17 00:00:00 2001 From: "SPEARS, DUSTIN (ds443n)" Date: Fri, 11 Aug 2023 14:29:35 -0400 Subject: [PATCH] Wait for new ovs ctl file Sometimes the poststart function on a pod restart completes too quickly, resulting in chown command running on the incorrect file. Change-Id: I2eca5b148f13c48314501c955723bf759ffaa4fc --- openvswitch/Chart.yaml | 2 +- .../bin/_openvswitch-vswitchd.sh.tpl | 24 +++++++++++++++++++ openvswitch/values.yaml | 3 +++ releasenotes/notes/openvswitch.yaml | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/openvswitch/Chart.yaml b/openvswitch/Chart.yaml index 1a13925c5..d7733a43b 100644 --- a/openvswitch/Chart.yaml +++ b/openvswitch/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm OpenVSwitch name: openvswitch -version: 0.1.16 +version: 0.1.17 home: http://openvswitch.org icon: https://www.openstack.org/themes/openstack/images/project-mascots/Neutron/OpenStack_Project_Neutron_vertical.png sources: diff --git a/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl b/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl index f85d0c7cb..bd539f39d 100644 --- a/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl +++ b/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl @@ -107,13 +107,37 @@ function stop () { ovs-appctl -T1 -t /run/openvswitch/ovs-vswitchd.${PID}.ctl exit } +find_latest_ctl_file() { + latest_file="" + latest_file=$(ls -lt /run/openvswitch/*.ctl | awk 'NR==1 {if ($3 == "{{ .Values.conf.poststart.rootUser }}") print $NF}') + + echo "$latest_file" +} + function poststart () { # This enables the usage of 'ovs-appctl' from neutron-ovs-agent pod. + + # Wait for potential new ctl file before continuing + timeout={{ .Values.conf.poststart.timeout }} + start_time=$(date +%s) + while true; do + latest_ctl_file=$(find_latest_ctl_file) + if [ -n "$latest_ctl_file" ]; then + break + fi + current_time=$(date +%s) + if (( current_time - start_time >= timeout )); then + break + fi + sleep 1 + done + until [ -f $OVS_PID ] do echo "Waiting for file $OVS_PID" sleep 1 done + PID=$(cat $OVS_PID) OVS_CTL=/run/openvswitch/ovs-vswitchd.${PID}.ctl diff --git a/openvswitch/values.yaml b/openvswitch/values.yaml index 4c6971c22..68e9b42a8 100644 --- a/openvswitch/values.yaml +++ b/openvswitch/values.yaml @@ -208,6 +208,9 @@ manifests: secret_registry: true conf: + poststart: + timeout: 5 + rootUser: "root" openvswitch_db_server: ptcp_port: null ovs_other_config: diff --git a/releasenotes/notes/openvswitch.yaml b/releasenotes/notes/openvswitch.yaml index 3bc8c2364..c9c2bf097 100644 --- a/releasenotes/notes/openvswitch.yaml +++ b/releasenotes/notes/openvswitch.yaml @@ -17,4 +17,5 @@ openvswitch: - 0.1.14 Add buffer before accesses pid file - 0.1.15 Add buffer before accesses ovs controller pid socket - 0.1.16 Restore ServiceAccount to openvswitch pod + - 0.1.17 Add buffer to wait for potential new CTL file before running chown ...