-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add del bash for redundant ips (#2063)
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
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 |