Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions templates/common/_base/files/wait-for-node-ip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
mode: 0755
path: "/usr/local/bin/wait-for-node-ip.sh"
contents:
inline: |
#!/bin/bash
set -eux

wait_for_ip_bind() {
local ip=$1
local end_time=$((SECONDS + 60))
while [[ $SECONDS -lt $end_time ]]
do
random_port=$(shuf -i 50000-60000 -n 1)
echo "Trying to bind ${ip} on port ${random_port}"
exit_code=$(timeout 2s nc -l "${ip}" ${random_port}; echo $?)
if [[ exit_code -eq 124 ]]; then
echo "Address bound successfully"
exit 0
fi
sleep 10
done
echo "Failed to bind ${ip} after 60 seconds"
return 123
}

if [ ! -e /etc/nmstate/openshift/applied ]; then
# No need to do this if no NMState configuration was applied
exit 0
fi

# This logic is borrowed from configure-ovs.sh
# TODO: Find a platform-agnostic way to do this. It won't work on platforms where
# nodeip-configuration is not used.
ip=$(cat /run/nodeip-configuration/primary-ip)
if [[ "${ip}" == "" ]]; then
echo "No primary ip to bind was found"
exit 1
fi
wait_for_ip_bind "${ip}"

# Do not fail below because we don't know if we run on primary-v4 or primary-v6 platform.
# We only want to make sure that if nodeip-configuration detected an IP address, the
# address is usable.
ip=$(cat /run/nodeip-configuration/ipv4)
if [[ "${ip}" == "" ]]; then
echo "No ipv4 to bind was found"
else
wait_for_ip_bind "${ip}"
fi

ip=$(cat /run/nodeip-configuration/ipv6)
if [[ "${ip}" == "" ]]; then
echo "No ipv6 to bind was found"
else
wait_for_ip_bind "${ip}"
fi
31 changes: 0 additions & 31 deletions templates/common/_base/files/wait-for-primary-ip.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion templates/common/_base/units/mtu-migration.service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contents: |
Description=Configures interfaces and routes with temporary MTUs during MTU migration
Requires=openvswitch.service ovs-configuration.service
Wants=NetworkManager-wait-online.service
After=NetworkManager-wait-online.service openvswitch.service network.service ovs-configuration.service wait-for-primary-ip.service
After=NetworkManager-wait-online.service openvswitch.service network.service ovs-configuration.service wait-for-node-ip.service
Before=kubelet-dependencies.target node-valid-hostname.service

[Service]
Expand Down
6 changes: 3 additions & 3 deletions templates/common/_base/units/wait-for-primary-ip.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: wait-for-primary-ip.service
name: wait-for-node-ip.service
enabled: true
contents: |
[Unit]
Description=Ensure primary IP is assigned and usable
Description=Ensure node IP(s) are assigned and usable
Requires=nmstate.service
After=nmstate.service
Before=kubelet-dependencies.target
Expand All @@ -14,7 +14,7 @@ contents: |
# available in systemd v244 and higher.
ExecStart=/bin/bash -c " \
until \
/usr/local/bin/wait-for-primary-ip.sh; \
/usr/local/bin/wait-for-node-ip.sh; \
do \
sleep 10; \
done"
Expand Down