diff --git a/Dockerfile b/Dockerfile index a751b6c..5b34f46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,33 @@ -FROM ctelfer/swarmctl:latest -RUN apk add --update bash docker jq +FROM golang:1.11-alpine as build-swarmctl +WORKDIR /go/src/github.com/docker + +RUN apk add --no-cache --update bash ca-certificates curl make git openssh-client +RUN git clone https://github.com/docker/swarmkit.git swarmkit && cd swarmkit && make bin/swarmctl && cp bin/swarmctl /usr/bin/swarmctl && rm -rf /go/src/github.com/docker/swarmkit + +FROM alpine:3.9 as build-protoc +ARG PROTOC_VERSION=3.6.1 +RUN apk add --update --no-cache unzip curl +# download and install protoc binary and .proto files +RUN curl --silent --show-error --location --output protoc.zip \ + https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip \ + && unzip -d /usr/local protoc.zip include/\* bin/\* \ + && rm -f protoc.zip + +FROM alpine:3.9 as build-docker +ARG DOCKER_CLIENT_VERSION=18.09.1 +RUN apk add --update --no-cache curl +RUN curl -SsL --output docker.tgz \ + https://download.docker.com/linux/static/stable/x86_64/docker-$DOCKER_CLIENT_VERSION.tgz \ + && tar xvzf docker.tgz \ + && cp docker/docker /usr/bin/docker \ + && rm -f docker.tgz + +FROM alpine:3.9 +RUN apk add --no-cache --update bash jq +# WORKDIR /go/src/github.com/docker +# RUN git clone https://github.com/docker/swarmkit.git swarmkit && cd swarmkit && make bin/swarmctl && cp bin/swarmctl /usr/bin/swarmctl && rm -rf /go/src/github.com/docker/swarmkit +COPY --from=build-swarmctl /usr/bin/swarmctl /usr/bin +COPY --from=build-protoc /usr/local/. /usr/local +COPY --from=build-docker /usr/bin/docker /usr/bin COPY ip-util-check /usr/bin -ENTRYPOINT [ "/usr/bin/ip-util-check" ] +CMD [ "/usr/bin/ip-util-check" ] diff --git a/README.md b/README.md index 801d37b..77e6188 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,29 @@ The script flags several potential conditions for each overlay: cluster size scales up to a certain number of nodes * IP address space is allocated to > 80% capacity +#### Note: +Under certain conditions, it may not be possible to accurately +count the number of IP addresses on a network due to Docker's +networking state distribution architecture. + +Gossip protocol only distributes network programming to nodes that +participate in an overlay network. A node must have a container or +service task scheduled on it attached to an overlay network to be +considered an overlay network peer. Manager nodes that are not running +workloads may not be able to accurately count the number of IP addresses +on overlay networks scheduled on worker nodes. In this case, we approximate. Building the Container ====================== -docker image build -t docker/ip-util-check . - +``` +docker build -t docker/ip-util-check . +``` Running the Container ===================== - - docker run -it --rm \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v /var/run/docker/swarm/control.sock:/var/run/swarmd.sock \ - docker/ip-util-check +``` +docker run -it --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /var/run/docker/swarm/control.sock:/var/run/swarmd.sock \ + docker/ip-util-check +``` diff --git a/ip-util-check b/ip-util-check index 53e69f7..6e80861 100755 --- a/ip-util-check +++ b/ip-util-check @@ -68,10 +68,11 @@ for net in $NETS ; do NET2NAME[$net]=$(echo $networkInspect | jq -r '.[].Name') set +e 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 + + if [ -z "${NET2SUB[$net]}" ] ; then + NET2SUB[$net]=$(/usr/bin/swarmctl network inspect ${NET2NAME[$net]} | grep Subnet | awk -F ": " '{print $2}' 2>/dev/null) + fi + set -e NET2CAP[$net]=0 NET2NCIP[$net]=0 NET2NVIP[$net]=0