File tree Expand file tree Collapse file tree 2 files changed +89
-0
lines changed Expand file tree Collapse file tree 2 files changed +89
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Delete a docker container with network namespace cleaned up by the Azure CNI plugin.
4+ # Example usage: ./docker-run.sh ubuntu default
5+
6+ if [ $# -ne 2 ]; then
7+ echo " usage: docker-run.sh <container-name> <namespace>"
8+ exit 1
9+ fi
10+
11+ pid=$( docker inspect -f ' {{ .State.Pid }}' $1 )
12+ netnspath=/proc/$pid /ns/net
13+ contid=$( docker inspect -f ' {{ .Id }}' $1 )
14+ export CNI_CONTAINERID=$contid
15+
16+ netns=netnspath
17+ export CNI_PATH=' /opt/cni/bin'
18+ export CNI_COMMAND=' DEL'
19+ export PATH=$CNI_PATH :$PATH
20+ export CNI_NETNS=$netns
21+ args=$( printf " K8S_POD_NAMESPACE=%s;K8S_POD_NAME=%s" $2 $1 )
22+ export CNI_ARGS=$args
23+ export CNI_IFNAME=' eth0'
24+
25+
26+ config=$( jq ' .plugins[0]' /etc/cni/net.d/10-azure.conflist)
27+ name=$( jq -r ' .name' /etc/cni/net.d/10-azure.conflist)
28+ config=$( echo $config | jq --arg name $name ' . + {name: $name}' )
29+ cniVersion=$( jq -r ' .cniVersion' /etc/cni/net.d/10-azure.conflist)
30+ config=$( echo $config | jq --arg cniVersion $cniVersion ' . + {cniVersion: $cniVersion}' )
31+
32+ res=$( echo $config | azure-vnet)
33+
34+
35+ if [ $? -ne 0 ]; then
36+ errmsg=$( echo $res | jq -r ' .msg' )
37+ if [ -z " $errmsg " ]; then
38+ errmsg=$res
39+ fi
40+ echo " ${name} : error executing $CNI_COMMAND : $errmsg "
41+ exit 1
42+ elif [[ ${DEBUG} -gt 0 ]]; then
43+ echo ${res} | jq -r .
44+ fi
45+
46+
47+ docker rm -f $1
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Run a docker container with network namespace set up by the Azure CNI plugin.
4+ # Example usage: ./docker-run.sh ubuntu default sushantsharma/ubuntu-s5
5+
6+ if [ $# -ne 3 ]; then
7+ echo " usage: docker-run.sh <container-name> <namespace> <image>"
8+ exit 1
9+ fi
10+
11+ contid=$( docker run -d --name $1 --net=none $3 /bin/sleep 10000000)
12+ export CNI_CONTAINERID=$contid
13+ pid=$( docker inspect -f ' {{ .State.Pid }}' $contid )
14+ netns=/proc/$pid /ns/net
15+
16+ export CNI_PATH=' /opt/cni/bin'
17+ export CNI_COMMAND=' ADD'
18+ export PATH=$CNI_PATH :$PATH
19+ export CNI_NETNS=$netns
20+ args=$( printf " K8S_POD_NAMESPACE=%s;K8S_POD_NAME=%s" $2 $1 )
21+ export CNI_ARGS=$args
22+ export CNI_IFNAME=' eth0'
23+
24+ config=$( jq ' .plugins[0]' /etc/cni/net.d/10-azure.conflist)
25+ name=$( jq -r ' .name' /etc/cni/net.d/10-azure.conflist)
26+ config=$( echo $config | jq --arg name $name ' . + {name: $name}' )
27+ cniVersion=$( jq -r ' .cniVersion' /etc/cni/net.d/10-azure.conflist)
28+ config=$( echo $config | jq --arg cniVersion $cniVersion ' . + {cniVersion: $cniVersion}' )
29+
30+ res=$( echo $config | azure-vnet)
31+
32+ if [ $? -ne 0 ]; then
33+ errmsg=$( echo $res | jq -r ' .msg' )
34+ if [ -z " $errmsg " ]; then
35+ errmsg=$res
36+ fi
37+ echo " ${name} : error executing $CNI_COMMAND : $errmsg "
38+ exit 1
39+ elif [[ ${DEBUG} -gt 0 ]]; then
40+ echo ${res} | jq -r .
41+ fi
42+
You can’t perform that action at this time.
0 commit comments