Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from fcrisciani/tweaks
Browse files Browse the repository at this point in the history
Simplified the script output
  • Loading branch information
mavenugo authored Nov 6, 2018
2 parents f6fc035 + c9a8e84 commit 520a5c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ The script flags several potential conditions for each overlay:

Building the Container
======================
docker image build -t ctelfer/ip-util-check .
docker image build -t docker/ip-util-check .


Running the Container
=====================

docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock \
ctelfer/ip-util-check
docker/ip-util-check
41 changes: 21 additions & 20 deletions ip-util-check
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ set -e

# Per-network state keyed on network ID
#
declare -A NET2SUB # list of subnets for each overlay network
declare -A NET2CAP # network capacity of each overlay network
declare -A NET2NAME # network name of each overlay network
declare -A NET2NCIP # number of container IP addresses for each overlay network
declare -A NET2NVIP # number of virtuail IP addresses for each overlay network
declare -A NET2SUB # list of subnets for each overlay network
declare -A NET2CAP # network capacity of each overlay network
declare -A NET2NAME # network name of each overlay network
declare -A NET2NCIP # number of container IP addresses for each overlay network
declare -A NET2NVIP # number of virtual IP addresses for each overlay network
declare -A NET2NNODES # number of nodes where the overlay is currently used


# Report the general IP utilization status of an overlay network
Expand All @@ -24,20 +25,18 @@ report() {
echo "Network ${NET2NAME[$1]}/$1 has no assigned IP addresses"
echo " Network OK"
else
USE=$(( ${NET2NCIP[$1]} + ${NET2NVIP[$1]} ))
SAFECAP=$(( (${NET2CAP[$1]} - ${NET2NVIP[$1]}) / 2 ))
echo "Network ${NET2NAME[$1]}/$1 has an IP address capacity of ${NET2CAP[$1]} and uses $USE addresses"

if [ $(( $USE + $NNODES )) -ge ${NET2CAP[$1]} ] ; then
echo " ERROR: network will be over capacity if upgrading Docker Enterprise engine version 18.09"
echo " or later."
elif [ $(( ${NET2NCIP[$1]} * 2 )) -ge $SAFECAP ] ; then
HDRM=$(( ${NET2CAP[$1]} - ${NET2NCIP[$1]} - ${NET2NVIP[$1]} ))
echo " WARNING: network could exhaust IP addresses if the cluster scales to $HDRM or more nodes"
elif [ ${NET2NCIP[$1]} -ge $(( $SAFECAP * 8 / 10 )) ] ; then
echo " WARNING: network using more than 80% of safe IP capacity ($SAFECAP)"
USE=$(( ${NET2NCIP[$1]} + ${NET2NVIP[$1]} )) # how many IPs are currently in use
SAFECAP=$(( ${NET2CAP[$1]} * 75 / 100 )) # safe capacity is the 75% of the whole address space
HDRM=$(( ${NET2CAP[$1]} - $USE - ${NET2NNODES[$1]})) # how many IPs are currently free in the network
echo "Network ${NET2NAME[$1]}/$1 has an IP address capacity of ${NET2CAP[$1]} and uses $USE addresses spanning over ${NET2NNODES[$1]} nodes"

if [ $(( $USE + ${NET2NNODES[$1]} )) -ge ${NET2CAP[$1]} ] ; then
echo " ERROR: network will be over capacity if upgrading Docker Enterprise engine version 18.09 or later"
elif [ $(( $USE + ${NET2NNODES[$1]} )) -ge $SAFECAP ] ; then
echo -n " WARNING: network is using more than the 75% of the total space. "
echo "Remaining only $HDRM IPs after upgrade"
else
echo " Network OK: network support up to $(( $SAFECAP - ${NET2NCIP[$1]} )) additional tasks safely"
echo " Network OK: network will have $(( $SAFECAP - $USE - ${NET2NNODES[$1]} )) available IPs before passing the 75% subnet use"
fi
fi
}
Expand All @@ -53,16 +52,18 @@ SVCIDS=$(docker service ls -q)

echo "Gathering overlay network information"
for net in $NETS ; do
NET2NAME[$net]=$(docker network inspect $net | jq -r '.[].Name')
networkInspect=$( docker network inspect $net )
NET2NAME[$net]=$(echo $networkInspect | jq -r '.[].Name')
set +e
NET2SUB[$net]=$(docker network inspect $net | jq -r '.[].IPAM.Config[].Subnet' 2>/dev/null)
NET2SUB[$net]=$(echo $networkInspect | jq -r '.[].IPAM.Config[].Subnet' 2>/dev/null)
if [ -z "${NET2SUB[$net]}" ] ; then
NET2SUB[$net]=$(docker network inspect ${NET2NAME[$net]} | jq -r '.[].IPAM.Config[].Subnet' 2>/dev/null)
fi
set -e
NET2CAP[$net]=0
NET2NCIP[$net]=0
NET2NVIP[$net]=0
NET2NNODES[$net]=$( echo $networkInspect | jq -r '.[].Peers | length' )
for sub in ${NET2SUB[$net]} ; do
pfxlen=$(echo $sub | awk -F / '{print $2}')
subcap=$(( (1 << (32 - $pfxlen)) - 3 ))
Expand Down

0 comments on commit 520a5c0

Please sign in to comment.