Skip to content

Instantly share code, notes, and snippets.

@brennovich
Forked from phspagiari/release_ips.sh
Created April 19, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennovich/3b87cebae4ccc2655a6ab8f536cdb705 to your computer and use it in GitHub Desktop.
Save brennovich/3b87cebae4ccc2655a6ab8f536cdb705 to your computer and use it in GitHub Desktop.
Release Calico unused IPs from CIDR Block (Bug v3.3.x)
#!/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