-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix gateway datapath disrupt on update
Reimplementing the vswitchd reload using separate start and stop scripts so that it can be executed partially between consecutives instances of the pod. To avoid disruptions, it runs ovs save-flows command on the stop-vswitchd script, saving the resulting backup on a mounted folder from the host and then loading that backup on the start script. For this to succeed, the script needs to set the flow-restore-wait flag from ovs to true while loading the flows. Note that ovs save-flows command needs to have ovsdb-server running, so a semaphore like mechanism was added to ensure the ovsdb-server container is never deleted before ovs-vswitchd. Closes-Issue: OSPRH-6326
- Loading branch information
Showing
15 changed files
with
168 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2024 Red Hat Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
source $(dirname $0)/functions | ||
wait_for_ovsdb_server | ||
|
||
# The order - first wait for db server, then set -ex - is important. Otherwise, | ||
# wait_for_ovsdb_server interrim check would make the script exit. | ||
set -ex | ||
|
||
# Configure encap IP. | ||
OVNEncapIP=$(ip -o addr show dev {{ .OVNEncapNIC }} scope global | awk '{print $4}' | cut -d/ -f1) | ||
ovs-vsctl --no-wait set open . external-ids:ovn-encap-ip=${OVNEncapIP} | ||
|
||
# Before starting vswitchd, block it from flushing existing datapath flows. | ||
ovs-vsctl --no-wait set open_vswitch . other_config:flow-restore-wait=true | ||
|
||
# It's safe to start vswitchd now. Do it. | ||
# --detach to allow the execution to continue to restoring the flows. | ||
/usr/sbin/ovs-vswitchd --pidfile --mlockall --detach | ||
|
||
# Restore saved flows. | ||
if [ -f $FLOWS_RESTORE_SCRIPT ]; then | ||
# It's unsafe to leave these files in place if they fail once. Make sure we | ||
# remove them if the eval fails. | ||
trap cleanup_flows_backup EXIT | ||
eval "$(cat $FLOWS_RESTORE_SCRIPT)" | ||
trap - EXIT | ||
fi | ||
|
||
# It's also unsafe to leave these files after flow-restore-wait flag is removed | ||
# because the backup will become stale and if a container later crashes, it may | ||
# mistakenly try to restore from this old backup. | ||
cleanup_flows_backup | ||
|
||
# Now, inform vswitchd that we are done. | ||
ovs-vsctl remove open_vswitch . other_config flow-restore-wait | ||
|
||
# This is container command script. Block it from exiting, otherwise k8s will | ||
# restart the container again. | ||
sleep infinity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2024 Red Hat Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -ex | ||
source $(dirname $0)/functions | ||
|
||
# Clean up any previously created flow backups to avoid conflict with newly | ||
# generated backup. | ||
cleanup_flows_backup | ||
|
||
# Passing --real to mimic what upstream startup scripts do; maybe redundant. | ||
bridges=$(ovs-vsctl -- --real list-br) | ||
|
||
# Saving flows to avoid disrupting gateway datapath. | ||
mkdir $FLOWS_RESTORE_DIR | ||
TMPDIR=$FLOWS_RESTORE_DIR /usr/share/openvswitch/scripts/ovs-save save-flows $bridges > $FLOWS_RESTORE_SCRIPT | ||
|
||
# Once save-flows logic is complete it no longer needs ovsdb-server, this file | ||
# unlocks the db preStop script, working as a semaphore | ||
touch $SAFE_TO_STOP_OVSDB_SERVER_SEMAPHORE | ||
|
||
# Finally, stop vswitchd. | ||
/usr/share/openvswitch/scripts/ovs-ctl stop --no-ovsdb-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../common/assert_sample_deployment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../common/deploy_ovn.yaml |
9 changes: 9 additions & 0 deletions
9
tests/kuttl/tests/ovn_restart_flow/02-add-bridge-and-flows.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
commands: | ||
- script: | | ||
node=$(oc get nodes -o name|sort|head -1| sed "s|node/||g") | ||
controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs --field-selector spec.nodeName=$node -o name | head -1) | ||
oc rsh -n $NAMESPACE --container ovs-vswitchd $controller_pod ovs-vsctl --if-exists del-br br-test-flows || exit 1 | ||
oc rsh -n $NAMESPACE --container ovs-vswitchd $controller_pod ovs-vsctl add-br br-test-flows || exit 1 | ||
oc rsh -n $NAMESPACE --container ovs-vswitchd $controller_pod ovs-ofctl add-flow br-test-flows "table=100, priority=200 action=drop" || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../common/assert_sample_deployment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
commands: | ||
- script: | | ||
node=$(oc get nodes -o name|sort|head -1| sed "s|node/||g") | ||
controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs --field-selector spec.nodeName=$node -o name | head -1) | ||
oc delete -n $NAMESPACE $controller_pod |
17 changes: 17 additions & 0 deletions
17
tests/kuttl/tests/ovn_restart_flow/04-assert-flows-present.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Check for: | ||
# | ||
# - Check that the flow added to the test bridge "br-test-flows" is present | ||
# after the ovn-controller has been restarted. | ||
# Expected flow: "table=100, priority=200 actions=drop" | ||
|
||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestAssert | ||
timeout: 300 | ||
commands: | ||
- script: | | ||
node=$(oc get nodes -o name|sort|head -1| sed "s|node/||g") | ||
controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs --field-selector spec.nodeName=$node -o name | head -1) | ||
expected_flows="table=100, priority=200 actions=drop" | ||
oc rsh -n $NAMESPACE --container ovs-vswitchd $controller_pod ovs-ofctl dump-flows br-test-flows --no-stats | grep -q "$expected_flows" || exit 1 | ||
oc rsh -n $NAMESPACE --container ovs-vswitchd $controller_pod ovs-vsctl --if-exists del-br br-test-flows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../common/cleanup-ovn.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../common/errors_cleanup_ovn.yaml |