#!/bin/bash
# Script to check DNS configuration on a working worker node

echo "=== Working Worker Node DNS Check ==="

echo "1. Basic info:"
hostname
hostname -f
echo "Node IP: $(hostname -I)"

echo -e "\n2. DNS configuration:"
echo "--- /etc/resolv.conf ---"
cat /etc/resolv.conf

echo -e "\n3. Test DNS resolution:"
echo "Checking api-int.test01.kvant.cloud:"
nslookup api-int.test01.kvant.cloud 2>&1 | grep -A2 "Name:"
echo -e "\nChecking api.test01.kvant.cloud:"
nslookup api.test01.kvant.cloud 2>&1 | grep -A2 "Name:"

echo -e "\n4. Check /etc/hosts for manual entries:"
grep -E "(api|test01)" /etc/hosts 2>/dev/null || echo "No api entries in /etc/hosts"

echo -e "\n5. NetworkManager DNS configuration:"
nmcli con show --active | grep -E "(DNS|domain)"
echo -e "\nActive connections:"
nmcli con show --active

echo -e "\n6. Check if node is using cluster DNS (CoreDNS):"
# Check if using cluster DNS service IP
grep -E "172.30.0.10|10.96.0.10" /etc/resolv.conf && echo "Using cluster DNS" || echo "Not using cluster DNS"

echo -e "\n7. Boot parameters on this working node:"
cat /proc/cmdline | tr ' ' '\n' | grep -E "(nameserver|dns|ip=)"

echo -e "\n8. Check OVS/network configuration:"
ip addr show br-ex 2>/dev/null | grep inet || echo "br-ex not found or no IP"
sudo ovs-vsctl show 2>/dev/null | grep -E "(Bridge|Port)" || echo "OVS not configured"

echo -e "\n9. Check how DNS was configured during boot:"
sudo journalctl -b | grep -E "(resolv.conf|nameserver|DNS)" | head -20

echo -e "\n10. Compare with new node issue:"
echo "The new node (worker-lpar01) cannot resolve api-int.test01.kvant.cloud"
echo "Check if this working node has different DNS servers or manual /etc/hosts entries"