Last active
August 10, 2024 19:00
-
-
Save fl64/23c27836353c9065d01dc9763e9a7b19 to your computer and use it in GitHub Desktop.
tshoot VM network issues
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
#!/usr/bin/env bash | |
NAMESPACE="testcases" | |
SCRIPT_TEMPLATE=' | |
for VM in %%VMS%%; do | |
VM_NAME=$(echo ${VM} | cut -d% -f 1); | |
VM_IP=$(echo ${VM} | cut -d% -f 2); | |
VM_NODE=$(echo ${VM} | cut -d% -f 3); | |
PING_RESULT=$(ping -w 1 -c 2 ${VM_IP}); | |
echo ${PING_RESULT} | grep -q " 0% packet loss"; | |
if [[ $? -eq 0 ]]; then | |
echo -n "ping✅ " ; | |
else | |
echo -n "ping❌ " ; | |
fi; | |
NC_RESULT=$(nc -zvw2 ${VM_IP} 22 2>&1); | |
echo "${NC_RESULT}" | |
echo ${NC_RESULT} | grep -q "succeeded"; | |
if [[ $? -eq 0 ]]; then | |
echo -n "nc22✅ " ; | |
else | |
echo -n "nc22❌ " ; | |
fi; | |
echo "${VM_IP} ${VM_NAME} ${VM_NODE}"; | |
done | |
' | |
VMS=$(kubectl get -A vms -o json | jq '[ .items[] | .metadata.name+"%"+.status.ipAddress+"%"+.status.nodeName ] | join(" ")' -cr) | |
SCRIPT=$(echo ${SCRIPT_TEMPLATE} | sed "s/%%VMS%%/${VMS}/g") | |
echo "${VMS}" | |
echo "=========================================================================" | |
echo ${SCRIPT} | |
echo "=========================================================================" | |
for NODE in $(kubectl get nodes -o name | cut -d/ -f2); do | |
echo "=========================================================================" | |
echo "dev-rnd.${NODE}" | |
echo "=========================================================================" | |
#/usr/bin/ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 dev-rnd.${NODE} "ip r show table 1490" | |
/usr/bin/ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 dev-rnd.${NODE} "${SCRIPT}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment