Merge pull request #19 from Heavybullets8/dns-cleanup

Dns cleanup
This commit is contained in:
Heavybullets8 2022-09-01 04:41:16 +00:00 committed by GitHub
commit 70771d23ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,24 +4,25 @@
dns(){ dns(){
clear -x clear -x
echo "Generating DNS Names.." echo "Generating DNS Names.."
#ignored dependency pods, may need to add more in the future. # Ignore svclb
dep_ignore="\-cronjob\-|^kube-system|\ssvclb|NAME|\-memcached\-.[^custom\-app]|\-postgresql\-.[^custom\-app]|\-redis\-.[^custom\-app]|\-mariadb\-.[^custom\-app]|\-promtail\-.[^custom\-app]" dep_ignore='svclb-'
# Pulling pod names # Pulling pod names
mapfile -t main < <(k3s kubectl get pods -A | grep -Ev "$dep_ignore" | sort) k3s crictl pods --namespace ix -s Ready | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//' | grep -Ev -- "$dep_ignore" | sed '1d' >> dns_file
mapfile -t ixName < <(< dns_file awk '{print $4}' | sort -u )
# Pulling all ports # Pulling all ports
all_ports=$(k3s kubectl get service -A) all_ports=$(k3s kubectl get service -A)
clear -x clear -x
count=0 count=0
for i in "${main[@]}" for i in "${ixName[@]}"
do do
[[ count -le 0 ]] && echo -e "\n" && ((count++)) [[ count -le 0 ]] && echo -e "\n" && ((count++))
appName=$(echo "$i" | awk '{print $2}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//') appName=$(grep -E "\s$i\s" "dns_file" | awk '{print $3}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//' | head -n 1)
ixName=$(echo "$i" | awk '{print $1}')
port=$(echo "$all_ports" | grep -E "\s$appName\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}") port=$(echo "$all_ports" | grep -E "\s$appName\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}")
echo -e "$appName.$ixName.svc.cluster.local $port" echo -e "$appName $appName.$i.svc.cluster.local $port"
done | uniq | nl -b t | sed 's/\s\s\s$/- -------- ----/' | column -t -R 1 -N "#,DNS_Name,Port" -L done | nl -s ") " -b t | sed '0,/\s\s\s/{s/\s\s\s/- ---- -------- ----/}'| column -t -N "#,Name,DNS_Name,Port"
rm dns_file
} }
export -f dns export -f dns