Skip to content

Commit

Permalink
fix: add del bash for redundant ips (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Nov 24, 2022
1 parent 1c334c8 commit 0c66843
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions dist/images/del-redundant-ips.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# This is a script for deleting redundant crd IPS
# This script will exit with code 1 if check failed
# This script is recommended for regular check, i.e., crontab, in a temporary processing

set -euo pipefail

delIPSWithIP(){
IPS=()
IPNAME=$(kubectl get ips -o=jsonpath='{range .items[*]}{.spec.ipAddress}{","}{.metadata.name}{"\n"}{end}')
for ipname in $IPNAME
do
ARRIN=(${ipname//,/ })
if [ ${ARRIN[0]} == $1 ]; then
echo "delete ips " ${ARRIN[1]}
kubectl delete ips ${ARRIN[1]}
fi
done
}

IPS=()
IPSUBNET=$(kubectl get ips -o=jsonpath='{range .items[*]}{.spec.ipAddress}{","}{.spec.subnet}{"\n"}{end}')
for ipsubnet in $IPSUBNET
do
ARRIN=(${ipsubnet//,/ })
if [ ${ARRIN[1]} != "join" ]; then
IPS+=(${ARRIN[0]})
fi
done

PODS=()
PODIPNODEIP=$(kubectl get pods -A -o=jsonpath='{range .items[*]}{.status.podIP}{","}{.status.hostIP}{"\n"}{end}')
for podnode in $PODIPNODEIP
do
ARRIN=(${podnode//,/ })
if [ ${ARRIN[0]} != ${ARRIN[1]} ]; then
PODS+=(${ARRIN[0]})
fi
done

for ip in "${IPS[@]}"
do
IN=true
for pod in "${PODS[@]}"
do
if [ "$ip" == "$pod" ]; then
IN=false
continue
fi
done
if $IN; then
delIPSWithIP "$ip"
fi
done

0 comments on commit 0c66843

Please sign in to comment.