Skip to content

Commit d96d261

Browse files
Merge pull request #4854 from pperiyasamy/ipsec-connect-wait
OCPBUGS-52280, SDN-5330: Add ipsec connect wait service
2 parents 1bffe82 + 1fa5eaa commit d96d261

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
mode: 0755
2+
path: "/usr/local/bin/ipsec-connect-wait.sh"
3+
contents:
4+
inline: |
5+
#!/bin/bash
6+
set -x
7+
8+
if [ ! -e "/etc/ipsec.d/openshift.conf" ]; then
9+
exit 0
10+
fi
11+
12+
# Modify existing IPsec connection entries with "auto=start"
13+
# option and restart ipsec systemd service. This helps to
14+
# establish IKE SAs for the existing IPsec connections with
15+
# peer nodes. This option will be deleted from connections
16+
# once ovs-monitor-ipsec process spinned up on the node by
17+
# ovn-ipsec-host pod, but still it won't reestablish IKE SAs
18+
# again with peer nodes, so it shouldn't be a problem.
19+
if ! grep -q "auto=start" /etc/ipsec.d/openshift.conf; then
20+
sed -i '/^.*conn ovn.*$/a\ auto=start' /etc/ipsec.d/openshift.conf
21+
fi
22+
chroot /proc/1/root ipsec restart
23+
24+
# Wait for upto 60s to get IPsec SAs to establish with peer nodes.
25+
timeout=60
26+
elapsed=0
27+
desiredconn=""
28+
establishedsa=""
29+
while [[ $elapsed -lt $timeout ]]; do
30+
desiredconn=$(grep -E '^\s*conn\s+' /etc/ipsec.d/openshift.conf | grep -v '%default' | awk '{print $2}' | tr ' ' '\n' | sort | tr '\n' ' ')
31+
establishedsa=$(ipsec showstates | grep STATE_V2_ESTABLISHED_CHILD_SA | grep -o '"[^"]*"' | sed 's/"//g' | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
32+
if [ "$desiredconn" == "$establishedsa" ]; then
33+
echo "IPsec SAs are established for desired connections after ${elapsed}s"
34+
break
35+
else
36+
echo "IPsec SAs are not established yet, total waited time ${elapsed}s"
37+
sleep 2s
38+
fi
39+
elapsed=$((elapsed + 2))
40+
done
41+
42+
if [[ $elapsed -ge $timeout ]]; then
43+
echo "Timed out waiting, some connections are not established, desired conns $desiredconn, established conns $establishedsa"
44+
fi

templates/common/_base/units/ipsec.service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dropins:
44
contents: |
55
[Unit]
66
After=ovs-configuration.service
7+
Before=crio.service
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: wait-for-ipsec-connect.service
2+
enabled: true
3+
contents: |
4+
[Unit]
5+
Description=Ensure IKE SA established for existing IPsec connections.
6+
After=ipsec.service
7+
Before=kubelet-dependencies.target node-valid-hostname.service
8+
9+
[Service]
10+
Type=oneshot
11+
ExecStart=/usr/local/bin/ipsec-connect-wait.sh
12+
StandardOutput=journal+console
13+
StandardError=journal+console
14+
15+
[Install]
16+
WantedBy=ipsec.service

0 commit comments

Comments
 (0)