Skip to content

Commit b886060

Browse files
committed
[ovn-controller] Change startup mechanism of ovs pods
This commit aims to modify the starting scripts of the ovn-controller-ovs daemonset. This is done to allow modifying the RollingUpdate Strategy to not allow any Unavailable pod during update, what this will cause is that during an update to the pod (delete old one and create new one) instead of first deleting the first one and then deleting the next one, it will create the new pod while the old one is running. Due to how the startup scritps works currently this is not allowed. The reason behind this is to try to lower the downtime observed if the environment is using centralized floating ip during an update. With this commit the ovn-controller-ovs will share the PID namespace with the host, in order to allow signaling between old/new pod. Another change is adding an STATE that the containers (ovsdb-server, ovs-vswitchd and ovsdb-server-init) will handle internally. The differents states are: - NULL (No file): will happen the fist time ds is created on the oc worker. - INIT: First time init-ovsdb-server is executed on the oc worker. - OVSDB_SERVER: once ovsdb-server pod has run the startup script - RUNNING: Once ovsdb-server is up and ovs-vswitchd has run the startup script. - UPDATE: Once a new pod is created and ovsdb-server-init has run. - RESTART_VSWITCH: After ovsdb-server-init has finished, new ovsdb-server pod has stopped the old ovs-vswitchd process. - RESTART_DBSERVER: After old ovs-vswitchd has been restarted the old ovsdb-server is also stop. The normal flow of states is the following: NULL -> INIT -> OVSDB_SERVER -> RUNNING Scale down: If the oc worker is deleted the DS and all the pods and mount points will be deleted, in case of node being up again it should start from NULL Update: RUNNING -> (Change on CR) -> UPDATE -> RESTART_VSWITCHD -> RESTART_DBSERVER -> OVSDB_SERVER -> RUNNING Jira: OSPRH-11636 Related: OSPRH-10821
1 parent 0c6c799 commit b886060

File tree

11 files changed

+215
-17
lines changed

11 files changed

+215
-17
lines changed

api/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ require (
6969
)
7070

7171
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
72+
73+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 //allow-merging

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 h1:UG6y5DfMsbbWDm6/ZJWWGRXrxAeNoskn4N0XVlhi8Gw=
2+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
13
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
24
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
35
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
@@ -80,8 +82,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
8082
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
8183
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 h1:wb2zsr9x9LantNLN/9dmYM42c3yLq3QuzsoOlGpDUxM=
8284
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4/go.mod h1:n5DV/lGE9DHryAJ+JLJSgUXI2QHTj+aN4KoeSNC3PfU=
83-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb h1:UAFYEHnbyhO0+yymquFmIqxc9QGji9mzreuYrDS1Ev4=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
8585
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8686
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8787
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

controllers/ovncontroller_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
612612
instance.Status.DesiredNumberScheduled = dset.GetDaemonSet().Status.DesiredNumberScheduled
613613
instance.Status.NumberReady = dset.GetDaemonSet().Status.NumberReady
614614

615-
// Define a new DaemonSet object for OVS (ovsdb-server + ovs-vswitchd)
616615
ovsdset := daemonset.NewDaemonSet(
617616
ovncontroller.CreateOVSDaemonSet(instance, inputHash, ovsServiceLabels, serviceAnnotations, topology),
618617
time.Duration(5)*time.Second,

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,5 @@ replace github.com/openstack-k8s-operators/ovn-operator/api => ./api
8383
// mschuppert: map to latest commit from release-4.16 tag
8484
// must consistent within modules and service operators
8585
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
86+
87+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 //allow-merging

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 h1:UG6y5DfMsbbWDm6/ZJWWGRXrxAeNoskn4N0XVlhi8Gw=
2+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
13
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
24
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
35
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
@@ -78,8 +80,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
7880
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
7981
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4 h1:wb2zsr9x9LantNLN/9dmYM42c3yLq3QuzsoOlGpDUxM=
8082
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250319162810-463dd75a4cc4/go.mod h1:n5DV/lGE9DHryAJ+JLJSgUXI2QHTj+aN4KoeSNC3PfU=
81-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb h1:UAFYEHnbyhO0+yymquFmIqxc9QGji9mzreuYrDS1Ev4=
82-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
8383
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20250315090821-34e570d2d5fb h1:7ADU3ZLE0l9/3A5l0jzAZt9XywzchosoY/m7VlFWu3I=
8484
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20250315090821-34e570d2d5fb/go.mod h1:oKvVb28i6wwBR5uQO2B2KMzZnCFTPCUCj31c5Zvz2lo=
8585
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

pkg/ovncontroller/daemonset.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
appsv1 "k8s.io/api/apps/v1"
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/util/intstr"
2728
"k8s.io/utils/ptr"
2829
)
2930

@@ -236,6 +237,27 @@ func CreateOVSDaemonSet(
236237
envVars := map[string]env.Setter{}
237238
envVars["CONFIG_HASH"] = env.SetValue(configHash)
238239

240+
volumes := []corev1.Volume{}
241+
mounts := []corev1.VolumeMount{}
242+
243+
// add OVN dbs cert and CA
244+
if instance.Spec.TLS.Enabled() {
245+
svc := tls.Service{
246+
SecretName: *instance.Spec.TLS.GenericService.SecretName,
247+
CertMount: ptr.To(ovn_common.OVNDbCertPath),
248+
KeyMount: ptr.To(ovn_common.OVNDbKeyPath),
249+
CaMount: ptr.To(ovn_common.OVNDbCaCertPath),
250+
}
251+
volumes = append(volumes, svc.CreateVolume(ovnv1.ServiceNameOVNController))
252+
mounts = append(mounts, svc.CreateVolumeMounts(ovnv1.ServiceNameOVNController)...)
253+
254+
// add CA bundle if defined
255+
if instance.Spec.TLS.CaBundleSecretName != "" {
256+
volumes = append(volumes, instance.Spec.TLS.CreateVolume())
257+
mounts = append(mounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
258+
}
259+
}
260+
239261
initContainers := []corev1.Container{
240262
{
241263
Name: "ovsdb-server-init",
@@ -250,7 +272,7 @@ func CreateOVSDaemonSet(
250272
Privileged: &privileged,
251273
},
252274
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
253-
VolumeMounts: GetOVSDbVolumeMounts(),
275+
VolumeMounts: append(GetOVSDbVolumeMounts(), mounts...),
254276
},
255277
}
256278

@@ -276,7 +298,7 @@ func CreateOVSDaemonSet(
276298
Privileged: &privileged,
277299
},
278300
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
279-
VolumeMounts: GetOVSDbVolumeMounts(),
301+
VolumeMounts: append(GetOVSDbVolumeMounts(), mounts...),
280302
// TODO: consider the fact that resources are now double booked
281303
Resources: instance.Spec.Resources,
282304
LivenessProbe: ovsDbLivenessProbe,
@@ -303,7 +325,7 @@ func CreateOVSDaemonSet(
303325
Privileged: &privileged,
304326
},
305327
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
306-
VolumeMounts: GetVswitchdVolumeMounts(),
328+
VolumeMounts: append(GetVswitchdVolumeMounts(), mounts...),
307329
// TODO: consider the fact that resources are now double booked
308330
Resources: instance.Spec.Resources,
309331
LivenessProbe: ovsVswitchdLivenessProbe,
@@ -312,6 +334,9 @@ func CreateOVSDaemonSet(
312334
},
313335
}
314336

337+
maxUnavailable := intstr.FromInt32(0)
338+
maxSurge := intstr.FromInt32(1)
339+
315340
daemonset := &appsv1.DaemonSet{
316341
ObjectMeta: metav1.ObjectMeta{
317342
Name: ovnv1.ServiceNameOVS,
@@ -327,9 +352,17 @@ func CreateOVSDaemonSet(
327352
},
328353
Spec: corev1.PodSpec{
329354
ServiceAccountName: instance.RbacResourceName(),
355+
HostPID: true,
330356
InitContainers: initContainers,
331357
Containers: containers,
332-
Volumes: GetOVSVolumes(instance.Name, instance.Namespace),
358+
Volumes: append(GetOVSVolumes(instance.Name, instance.Namespace), volumes...),
359+
},
360+
},
361+
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
362+
Type: appsv1.RollingUpdateDaemonSetStrategyType,
363+
RollingUpdate: &appsv1.RollingUpdateDaemonSet{
364+
MaxUnavailable: &maxUnavailable,
365+
MaxSurge: &maxSurge,
333366
},
334367
},
335368
},

templates/ovncontroller/bin/init-ovsdb-server.sh

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,67 @@ set -ex
1818
source $(dirname $0)/functions
1919
trap wait_for_db_creation EXIT
2020

21+
function init_ovsdb_server {
22+
# Initialize or upgrade database if needed
23+
CTL_ARGS="--system-id=random --no-ovs-vswitchd"
24+
/usr/share/openvswitch/scripts/ovs-ctl start $CTL_ARGS
25+
/usr/share/openvswitch/scripts/ovs-ctl stop $CTL_ARGS
26+
27+
if [ ! -f /var/lib/openvswitch/already_executed ]; then
28+
# If file was not present, set status INIT
29+
echo "INIT" > /var/lib/openvswitch/already_executed
30+
fi
31+
32+
wait_for_db_creation
33+
trap - EXIT
34+
}
35+
36+
TLSOptions="--certificate=/etc/pki/tls/certs/ovndb.crt --private-key=/etc/pki/tls/private/ovndb.key --ca-cert=/etc/pki/tls/certs/ovndbca.crt"
37+
DBOptions="--db ssl:ovsdbserver-nb.openstack.svc.cluster.local:6641"
38+
2139
# If db file is empty, remove it; otherwise service won't start.
2240
# See https://issues.redhat.com/browse/FDP-689 for more details.
2341
if ! [ -s ${DB_FILE} ]; then
2442
rm -f ${DB_FILE}
2543
fi
26-
# Initialize or upgrade database if needed
27-
CTL_ARGS="--system-id=random --no-ovs-vswitchd"
28-
/usr/share/openvswitch/scripts/ovs-ctl start $CTL_ARGS
29-
/usr/share/openvswitch/scripts/ovs-ctl stop $CTL_ARGS
3044

31-
wait_for_db_creation
32-
trap - EXIT
45+
# Easier debug
46+
sleep 10
47+
48+
# Check if file is created, if not means it's first execution
49+
if [ -f /var/lib/openvswitch/already_executed ]; then
50+
# Need to double check that ovsdb-server and vswitchd are actually running
51+
# (That pod was not unhealty and it got destroyed)
52+
# In the following steps we need ovsdb-server to be running, check pid file
53+
if [ ! -f /run/openvswitch/ovsdb-server.pid ]; then
54+
# No PID file, start as normal
55+
echo "No PID file found, init ovsdb_server as it's the only pod"
56+
init_ovsdb_server
57+
exit 0
58+
fi
59+
# File is created, no need to run ovs-ctl
60+
# Change state to "UPDATE"
61+
echo "UPDATE" > /var/lib/openvswitch/already_executed
62+
# Clear possible leftovers of past executions
63+
## Need to lower chassis priority
64+
# First get the system-id
65+
chassis_id=$(ovs-vsctl get Open_Vswitch . external_ids:system-id)
66+
nb_output=$(ovn-nbctl --no-leader-only $DBOptions $TLSOptions --columns=_uuid,priority find Gateway_Chassis chassis_name=$chassis_id)
67+
# Check that nbctl was executed correctly
68+
if [ $? -ne 0 ]; then
69+
echo "ERROR: ovn-nbctl find command failed"
70+
exit 1
71+
fi
72+
row_uuid=$(echo "$nb_output" | grep "_uuid" | cut -d':' -f2 | xargs)
73+
priority=$(echo "$nb_output" | grep "priority" | cut -d':' -f2 | xargs)
74+
# Save priority to be able to restore it later (It's overwritting, not appending, hence no check)
75+
echo $priority > /var/lib/openvswitch/old_priority
76+
# Set lower priority (lowest value possible 0)
77+
ovn-nbctl --no-leader-only $DBOptions $TLSOptions set Gateway_Chassis $row_uuid priority=0
78+
# Check that nbctl was executed correctly
79+
if [ $? -ne 0 ]; then
80+
echo "ERROR: ovn-nbctl set command failed"
81+
exit 1
82+
fi
83+
exit 0
84+
fi

templates/ovncontroller/bin/start-ovsdb-server.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,52 @@
1717
set -ex
1818
source $(dirname $0)/functions
1919

20+
echo "start ovsdb-server"
21+
sleep 3
22+
23+
# Check state
24+
if [ -f /var/lib/openvswitch/already_executed ]; then
25+
if [ $(cat /var/lib/openvswitch/already_executed) == "UPDATE" ]; then
26+
echo "In a middle of an upgrade"
27+
# Need to stop vswitch and dbserver
28+
# First stop vswitchd
29+
vswitchd_pid=$(cat /run/openvswitch/ovs-vswitchd.pid)
30+
# Stop vswitch
31+
echo "stopping vswitchd"
32+
bash /usr/local/bin/container-scripts/stop-vswitchd.sh
33+
echo "Done, stopped vswitchd"
34+
# Wait for vswitchd to end checking status
35+
while true; do
36+
if [ $(cat /var/lib/openvswitch/already_executed) == "RESTART_VSWITCHD" ]; then
37+
break
38+
fi
39+
sleep 0.1
40+
done
41+
echo "Status is already RESTART_VSWITCHD"
42+
bash /usr/local/bin/container-scripts/stop-ovsdb-server.sh
43+
echo "Done, stopped ovsdb-server"
44+
# vswitchd stopped
45+
# We still need to run the ovsdb-server in this new container, this can be done
46+
# with the flag --overwrite-pidfile but we need to ignore the next SIGTERM that will
47+
# send openshift, creating file to noop the stop-ovsdb-server.sh
48+
echo "setting flag to skip ovsdb-server stop"
49+
touch /var/lib/openvswitch/skip_stop_ovsdbserver
50+
else
51+
# It could happen that ovsdb-server or ovs-vwsitchd pod can't start correctly or can't get to running state
52+
# this would cause this script to be run with already_executed with an state different than "UPDATE"
53+
:
54+
fi
55+
fi
56+
2057
# Remove the obsolete semaphore file in case it still exists.
2158
cleanup_ovsdb_server_semaphore
2259

60+
# Set state to "OVSDB_SERVER"
61+
echo "OVSDB_SERVER" > /var/lib/openvswitch/already_executed
62+
2363
# Start the service
2464
ovsdb-server ${DB_FILE} \
25-
--pidfile \
65+
--pidfile --overwrite-pidfile \
2666
--remote=punix:/var/run/openvswitch/db.sock \
2767
--private-key=db:Open_vSwitch,SSL,private_key \
2868
--certificate=db:Open_vSwitch,SSL,certificate \

templates/ovncontroller/bin/start-vswitchd.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17+
sleep 3
18+
TLSOptions="--certificate=/etc/pki/tls/certs/ovndb.crt --private-key=/etc/pki/tls/private/ovndb.key --ca-cert=/etc/pki/tls/certs/ovndbca.crt"
19+
DBOptions="--db ssl:ovsdbserver-nb.openstack.svc.cluster.local:6641"
20+
21+
# Check if we're doing an update
22+
echo "Check if we're doing an update"
23+
if [ -f /var/lib/openvswitch/already_executed ]; then
24+
while true; do
25+
if [ $(cat /var/lib/openvswitch/already_executed) == "OVSDB_SERVER" ]; then
26+
break
27+
fi
28+
sleep 0.1
29+
done
30+
echo "OVSDBSERVER Already up, start script"
31+
fi
32+
1733
source $(dirname $0)/functions
1834
wait_for_ovsdb_server
1935

@@ -30,7 +46,7 @@ ovs-vsctl --no-wait set open_vswitch . other_config:flow-restore-wait=true
3046

3147
# It's safe to start vswitchd now. Do it.
3248
# --detach to allow the execution to continue to restoring the flows.
33-
/usr/sbin/ovs-vswitchd --pidfile --mlockall --detach
49+
/usr/sbin/ovs-vswitchd --pidfile --overwrite-pidfile --mlockall --detach
3450

3551
# Restore saved flows.
3652
if [ -f $FLOWS_RESTORE_SCRIPT ]; then
@@ -49,6 +65,30 @@ cleanup_flows_backup
4965
# Now, inform vswitchd that we are done.
5066
ovs-vsctl remove open_vswitch . other_config flow-restore-wait
5167

68+
# Restore the priority if this was changed during the update
69+
if [ -f /var/lib/openvswitch/old_priority ]; then
70+
echo "Using DBOptions: $DBOptions"
71+
echo "Using TLSOptions: $TLSOptions"
72+
priority=$(cat /var/lib/openvswitch/old_priority)
73+
echo "Restoring old priority, which was: $priority"
74+
chassis_id=$(ovs-vsctl get Open_Vswitch . external_ids:system-id)
75+
nb_output=$(ovn-nbctl --no-leader-only $DBOptions $TLSOptions --columns=_uuid,priority find Gateway_Chassis chassis_name=$chassis_id)
76+
err=$?
77+
if [ $err -ne 0 ]; then
78+
echo "Error while getting gateway chassis uuid $err"
79+
fi
80+
row_uuid=$(echo "$nb_output" | grep "_uuid" | cut -d':' -f2 | xargs)
81+
rm /var/lib/openvswitch/old_priority
82+
ovn-nbctl --no-leader-only $DBOptions $TLSOptions set Gateway_Chassis $row_uuid priority=$priority
83+
err=$?
84+
if [ $err -ne 0 ]; then
85+
echo "Error while setting gateway chassis priority ($priority), error: $err"
86+
fi
87+
fi
88+
89+
# Set state to "RUNNING"
90+
echo "RUNNING" > /var/lib/openvswitch/already_executed
91+
5292
# This is container command script. Block it from exiting, otherwise k8s will
5393
# restart the container again.
5494
sleep infinity

templates/ovncontroller/bin/stop-ovsdb-server.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17+
if [ -f /var/lib/openvswitch/skip_stop_ovsdbserver ]; then
18+
echo "Skipping stop script"
19+
rm /var/lib/openvswitch/skip_stop_ovsdbserver
20+
exit 0
21+
fi
22+
1723
set -ex
1824
source $(dirname $0)/functions
1925

@@ -26,5 +32,13 @@ while [ ! -f $SAFE_TO_STOP_OVSDB_SERVER_SEMAPHORE ]; do
2632
done
2733
cleanup_ovsdb_server_semaphore
2834

35+
while [ $(cat /var/log/openvswitch/already_executed) != "RESTART_VSWITCHD" ]; do
36+
# Wait to vswitchd container to finish it's stop process
37+
sleep 0.1
38+
done
39+
2940
# Now it's safe to stop db server. Do it.
3041
/usr/share/openvswitch/scripts/ovs-ctl stop --no-ovs-vswitchd
42+
43+
# Update state to "RESTART_DBSERVER"
44+
echo "RESTART_DBSERVER" > /var/lib/openvswitch/already_executed

templates/ovncontroller/bin/stop-vswitchd.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17+
if [ -f /var/lib/openvswitch/skip_stop_vswitchd ]; then
18+
echo "Skipping stop script"
19+
rm /var/lib/openvswitch/skip_stop_vswitchd
20+
exit 0
21+
fi
1722
set -ex
1823
source $(dirname $0)/functions
1924

@@ -32,5 +37,16 @@ TMPDIR=$FLOWS_RESTORE_DIR /usr/share/openvswitch/scripts/ovs-save save-flows $br
3237
# unlocks the db preStop script, working as a semaphore
3338
touch $SAFE_TO_STOP_OVSDB_SERVER_SEMAPHORE
3439

40+
# If it's comming from an update, it means that the
41+
# new pod, hence we're still missing the signal from the openshift. To avoid
42+
# running this script twice, create file to skip the following SIGTERM signal
43+
if [ -f /var/lib/openvswitch/already_executed ]; then
44+
if [ $(cat /var/lib/openvswitch/already_executed) == "UPDATE" ]; then
45+
touch /var/lib/openvswitch/skip_stop_vswitchd
46+
fi
47+
fi
48+
# Update state to "RESTART_VSWITCHD"
49+
echo "RESTART_VSWITCHD" > /var/lib/openvswitch/already_executed
50+
3551
# Finally, stop vswitchd.
3652
/usr/share/openvswitch/scripts/ovs-ctl stop --no-ovsdb-server

0 commit comments

Comments
 (0)