-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathsetup-p2p-addresses.sh
39 lines (30 loc) · 1.45 KB
/
setup-p2p-addresses.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
POD_NAME=$(echo $HOSTNAME)
if [ "${NETWORK_PUBLIC}" = "true" ]; then
# First try treating HOSTNAME as a pod name
NODE_NAME=$(kubectl get pod $POD_NAME -n ${NAMESPACE} -o jsonpath='{.spec.nodeName}' 2>/dev/null)
# If that fails, HOSTNAME might be the node name itself
if [ $? -ne 0 ]; then
echo "Could not find pod $POD_NAME, assuming $POD_NAME is the node name"
NODE_NAME=$POD_NAME
fi
EXTERNAL_IP=$(kubectl get node $NODE_NAME -o jsonpath='{.status.addresses[?(@.type=="ExternalIP")].address}')
if [ -z "$EXTERNAL_IP" ]; then
echo "Warning: Could not find ExternalIP, falling back to InternalIP"
EXTERNAL_IP=$(kubectl get node $NODE_NAME -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}')
fi
TCP_ADDR="${EXTERNAL_IP}:${P2P_TCP_PORT}"
UDP_ADDR="${EXTERNAL_IP}:${P2P_UDP_PORT}"
else
# Get pod IP for non-public networks
POD_IP=$(hostname -i)
TCP_ADDR="${POD_IP}:${P2P_TCP_PORT}"
UDP_ADDR="${POD_IP}:${P2P_UDP_PORT}"
fi
# Write addresses to file for sourcing
echo "export P2P_TCP_ANNOUNCE_ADDR=${TCP_ADDR}" > /shared/config/p2p-addresses
echo "export P2P_TCP_LISTEN_ADDR=0.0.0.0:${P2P_TCP_PORT}" >> /shared/config/p2p-addresses
echo "export P2P_UDP_ANNOUNCE_ADDR=${UDP_ADDR}" >> /shared/config/p2p-addresses
echo "export P2P_UDP_LISTEN_ADDR=0.0.0.0:${P2P_UDP_PORT}" >> /shared/config/p2p-addresses
echo "P2P addresses configured:"
cat /shared/config/p2p-addresses