-
-
Save brennovich/3b87cebae4ccc2655a6ab8f536cdb705 to your computer and use it in GitHub Desktop.
Release Calico unused IPs from CIDR Block (Bug v3.3.x)
This file contains hidden or 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
#!/bin/bash | |
# Works for /16 CIDR Blocks, change / upgrade the script if you need | |
CIDR_PREFIX="172.20" | |
for oct1 in {128..255}; do | |
# Generate a new list of used IPs on every block | |
calicoctl get wep --all-namespaces | awk '{print $4}' |cut -d "/" -f1 > valid_ips.txt | |
for oct2 in {1..254}; do | |
if grep "${CIDR_BLOCK}.$oct1.$oct2" ./valid_ips.txt; then | |
echo " - Skipping ${CIDR_BLOCK}.$oct1.$oct2" | |
continue | |
fi | |
echo " - Releasing ${CIDR_BLOCK}.$oct1.$oct2" | |
calicoctl ipam release --ip=${CIDR_BLOCK}.$oct1.$oct2 | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment