Browse code

Create support as a container

Containerize support.sh

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>

Flavio Crisciani authored on 2018/06/21 04:57:08
Showing 5 changed files
... ...
@@ -34,12 +34,14 @@ build-images:
34 34
 	docker build -f cmd/diagnostic/Dockerfile.client -t dockereng/network-diagnostic:onlyclient bin/
35 35
 	docker build -f cmd/diagnostic/Dockerfile.dind -t dockereng/network-diagnostic:17.12-dind bin/
36 36
 	docker build -f cmd/networkdb-test/Dockerfile -t dockereng/e2e-networkdb bin/
37
+	docker build -t dockereng/network-diagnostic:support.sh support/
37 38
 
38 39
 push-images: build-images
39 40
 	@echo "🐳 $@"
40 41
 	docker push dockereng/network-diagnostic:onlyclient
41 42
 	docker push dockereng/network-diagnostic:17.12-dind
42 43
 	docker push dockereng/e2e-networkdb
44
+	docker push dockereng/network-diagnostic:support.sh
43 45
 
44 46
 clean:
45 47
 	@echo "🐳 $@"
46 48
deleted file mode 100755
... ...
@@ -1,105 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-# Required tools
4
-DOCKER="${DOCKER:-docker}"
5
-NSENTER="${NSENTER:-nsenter}"
6
-BRIDGE="${BRIDGE:-bridge}"
7
-IPTABLES="${IPTABLES:-iptables}"
8
-IPVSADM="${IPVSADM:-ipvsadm}"
9
-IP="${IP:-ip}"
10
-
11
-networks=0
12
-containers=0
13
-ip_overlap=0
14
-
15
-NSDIR=/var/run/docker/netns
16
-
17
-function die {
18
-    echo $*
19
-    exit 1
20
-}
21
-
22
-function echo_and_run {
23
-  echo "#" "$@"
24
-  eval $(printf '%q ' "$@") < /dev/stdout
25
-}
26
-
27
-function check_ip_overlap {
28
-  inspect=$1
29
-  overlap=$(echo "$inspect_output" | grep "EndpointIP\|VIP" | cut -d':' -f2 | sort | uniq -c | grep -v "1 ")
30
-  if [ ! -z "$overlap" ]; then
31
-    echo -e "\n\n*** OVERLAP on Network ${networkID} ***";
32
-    echo -e "${overlap} \n\n"
33
-    ((ip_overlap++))
34
-  else
35
-    echo "No overlap"
36
-  fi
37
-}
38
-
39
-type -P ${DOCKER} > /dev/null || echo "This tool requires the docker binary"
40
-type -P ${NSENTER} > /dev/null || echo "This tool requires nsenter"
41
-type -P ${BRIDGE} > /dev/null || echo "This tool requires bridge"
42
-type -P ${IPTABLES} > /dev/null || echo "This tool requires iptables"
43
-type -P ${IPVSADM} > /dev/null || echo "This tool requires ipvsadm"
44
-type -P ${IP} > /dev/null || echo "This tool requires ip"
45
-
46
-if ${DOCKER} network inspect --help | grep -q -- --verbose; then
47
-    NETINSPECT_VERBOSE_SUPPORT="--verbose"
48
-else
49
-    NETINSPECT_VERBOSE_SUPPORT=""
50
-fi
51
-
52
-echo "Host iptables"
53
-echo_and_run ${IPTABLES} -w1 -n -v -L -t filter | grep -v '^$'
54
-echo_and_run ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
55
-echo_and_run ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
56
-printf "\n"
57
-
58
-echo "Host links addresses and routes"
59
-echo_and_run ${IP} -o link show
60
-echo_and_run ${IP} -o -4 address show
61
-echo_and_run ${IP} -4 route show
62
-printf "\n"
63
-
64
-echo "Overlay network configuration"
65
-for networkID in $(${DOCKER} network ls --no-trunc --filter driver=overlay -q) "ingress_sbox"; do
66
-    echo "nnn Network ${networkID}"
67
-    if [ "${networkID}" != "ingress_sbox" ]; then
68
-        nspath=(${NSDIR}/*-${networkID:0:10})
69
-        inspect_output=$(${DOCKER} network inspect ${NETINSPECT_VERBOSE_SUPPORT} ${networkID})
70
-        echo "$inspect_output"
71
-        check_ip_overlap $inspect_output
72
-    else
73
-        nspath=(${NSDIR}/${networkID})
74
-    fi
75
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -o -4 address show
76
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 route show
77
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 neigh show
78
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${BRIDGE} fdb show
79
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t filter | grep -v '^$'
80
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
81
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
82
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPVSADM} -l -n
83
-    printf "\n"
84
-    ((networks++))
85
-done
86
-
87
-echo "Container network configuration"
88
-for containerID in $(${DOCKER} container ls -q); do
89
-    echo "ccc Container ${containerID}"
90
-    ${DOCKER} container inspect ${containerID} --format 'Name:{{json .Name | printf "%s\n"}}Id:{{json .Id | printf "%s\n"}}Hostname:{{json .Config.Hostname | printf "%s\n"}}CreatedAt:{{json .Created | printf "%s\n"}}State:{{json .State|printf "%s\n"}}RestartCount:{{json .RestartCount | printf "%s\n" }}Labels:{{json .Config.Labels | printf "%s\n"}}NetworkSettings:{{json .NetworkSettings}}' | sed '/^State:/ {s/\\"/QUOTE/g; s/,"Output":"[^"]*"//g;}'
91
-    nspath=$(docker container inspect --format {{.NetworkSettings.SandboxKey}} ${containerID})
92
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -o -4 address show
93
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 route show
94
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 neigh show
95
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
96
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
97
-    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPVSADM} -l -n
98
-    printf "\n"
99
-    ((containers++))
100
-done
101
-
102
-echo -e "\n\n==SUMMARY=="
103
-echo -e "\t Processed $networks networks"
104
-echo -e "\t IP overlap found: $ip_overlap"
105
-echo -e "\t Processed $containers containers"
106 1
new file mode 100644
... ...
@@ -0,0 +1,49 @@
0
+FROM docker:18-dind
1
+
2
+RUN set -ex \
3
+    && echo "http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
4
+    && echo "http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
5
+    && apk update \
6
+    && apk add --no-cache \
7
+    tcpdump \
8
+    bridge-utils \
9
+    netcat-openbsd \
10
+    util-linux \
11
+    iptables \
12
+    iputils \
13
+    iproute2 \
14
+    iftop \
15
+    drill \
16
+    apache2-utils \
17
+    strace \
18
+    curl \
19
+    ethtool \
20
+    ipvsadm \
21
+    ngrep \
22
+    iperf \
23
+    nmap \
24
+    nmap-nping \
25
+    conntrack-tools \
26
+    socat \
27
+    busybox-extras \
28
+    tcptraceroute \
29
+    mtr \
30
+    fping \
31
+    liboping \
32
+    iptraf-ng \
33
+    dhcping \
34
+    nmap-nping \
35
+    net-snmp-tools \
36
+    python2 \
37
+    py2-virtualenv \
38
+    py-crypto \
39
+    scapy \
40
+    vim \
41
+    bird \
42
+    bash \
43
+    bind-tools
44
+
45
+WORKDIR /bin
46
+COPY support.sh .
47
+
48
+CMD /bin/support.sh
0 49
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Usage: docker run -v /var/run:/var/run  --network host --privileged dockereng/network-diagnostic:support.sh
0 1
new file mode 100755
... ...
@@ -0,0 +1,105 @@
0
+#!/usr/bin/env bash
1
+
2
+# Required tools
3
+DOCKER="${DOCKER:-docker}"
4
+NSENTER="${NSENTER:-nsenter}"
5
+BRIDGE="${BRIDGE:-bridge}"
6
+IPTABLES="${IPTABLES:-iptables}"
7
+IPVSADM="${IPVSADM:-ipvsadm}"
8
+IP="${IP:-ip}"
9
+
10
+networks=0
11
+containers=0
12
+ip_overlap=0
13
+
14
+NSDIR=/var/run/docker/netns
15
+
16
+function die {
17
+    echo $*
18
+    exit 1
19
+}
20
+
21
+function echo_and_run {
22
+  echo "#" "$@"
23
+  eval $(printf '%q ' "$@") < /dev/stdout
24
+}
25
+
26
+function check_ip_overlap {
27
+  inspect=$1
28
+  overlap=$(echo "$inspect_output" | grep "EndpointIP\|VIP" | cut -d':' -f2 | sort | uniq -c | grep -v "1 ")
29
+  if [ ! -z "$overlap" ]; then
30
+    echo -e "\n\n*** OVERLAP on Network ${networkID} ***";
31
+    echo -e "${overlap} \n\n"
32
+    ((ip_overlap++))
33
+  else
34
+    echo "No overlap"
35
+  fi
36
+}
37
+
38
+type -P ${DOCKER} > /dev/null || echo "This tool requires the docker binary"
39
+type -P ${NSENTER} > /dev/null || echo "This tool requires nsenter"
40
+type -P ${BRIDGE} > /dev/null || echo "This tool requires bridge"
41
+type -P ${IPTABLES} > /dev/null || echo "This tool requires iptables"
42
+type -P ${IPVSADM} > /dev/null || echo "This tool requires ipvsadm"
43
+type -P ${IP} > /dev/null || echo "This tool requires ip"
44
+
45
+if ${DOCKER} network inspect --help | grep -q -- --verbose; then
46
+    NETINSPECT_VERBOSE_SUPPORT="--verbose"
47
+else
48
+    NETINSPECT_VERBOSE_SUPPORT=""
49
+fi
50
+
51
+echo "Host iptables"
52
+echo_and_run ${IPTABLES} -w1 -n -v -L -t filter | grep -v '^$'
53
+echo_and_run ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
54
+echo_and_run ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
55
+printf "\n"
56
+
57
+echo "Host links addresses and routes"
58
+echo_and_run ${IP} -o link show
59
+echo_and_run ${IP} -o -4 address show
60
+echo_and_run ${IP} -4 route show
61
+printf "\n"
62
+
63
+echo "Overlay network configuration"
64
+for networkID in $(${DOCKER} network ls --no-trunc --filter driver=overlay -q) "ingress_sbox"; do
65
+    echo "nnn Network ${networkID}"
66
+    if [ "${networkID}" != "ingress_sbox" ]; then
67
+        nspath=(${NSDIR}/*-${networkID:0:10})
68
+        inspect_output=$(${DOCKER} network inspect ${NETINSPECT_VERBOSE_SUPPORT} ${networkID})
69
+        echo "$inspect_output"
70
+        check_ip_overlap $inspect_output
71
+    else
72
+        nspath=(${NSDIR}/${networkID})
73
+    fi
74
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -o -4 address show
75
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 route show
76
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 neigh show
77
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${BRIDGE} fdb show
78
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t filter | grep -v '^$'
79
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
80
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
81
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPVSADM} -l -n
82
+    printf "\n"
83
+    ((networks++))
84
+done
85
+
86
+echo "Container network configuration"
87
+for containerID in $(${DOCKER} container ls -q); do
88
+    echo "ccc Container ${containerID}"
89
+    ${DOCKER} container inspect ${containerID} --format 'Name:{{json .Name | printf "%s\n"}}Id:{{json .Id | printf "%s\n"}}Hostname:{{json .Config.Hostname | printf "%s\n"}}CreatedAt:{{json .Created | printf "%s\n"}}State:{{json .State|printf "%s\n"}}RestartCount:{{json .RestartCount | printf "%s\n" }}Labels:{{json .Config.Labels | printf "%s\n"}}NetworkSettings:{{json .NetworkSettings}}' | sed '/^State:/ {s/\\"/QUOTE/g; s/,"Output":"[^"]*"//g;}'
90
+    nspath=$(docker container inspect --format {{.NetworkSettings.SandboxKey}} ${containerID})
91
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -o -4 address show
92
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 route show
93
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IP} -4 neigh show
94
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t nat | grep -v '^$'
95
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPTABLES} -w1 -n -v -L -t mangle | grep -v '^$'
96
+    echo_and_run ${NSENTER} --net=${nspath[0]} ${IPVSADM} -l -n
97
+    printf "\n"
98
+    ((containers++))
99
+done
100
+
101
+echo -e "\n\n==SUMMARY=="
102
+echo -e "\t Processed $networks networks"
103
+echo -e "\t IP overlap found: $ip_overlap"
104
+echo -e "\t Processed $containers containers"