Skip to content

Instantly share code, notes, and snippets.

@phspagiari
Created April 11, 2019 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phspagiari/ede92744b1e69c069c595b7c4c6e7149 to your computer and use it in GitHub Desktop.
Save phspagiari/ede92744b1e69c069c595b7c4c6e7149 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