Add idempotency to setup-gateway.sh

Now docker container will not be run if it already
exists.

Change-Id: Ife797c0326d36e4c20a89014621b3a1f111ec51d
This commit is contained in:
Kostiantyn Kalynovskyi 2022-07-14 20:21:19 +00:00 committed by Kostyantyn Kalynovskyi
parent 431611d45e
commit 5b6192746a

View File

@ -32,8 +32,11 @@ sudo iptables -P FORWARD ACCEPT
DEFAULT_ROUTE_DEV=$(route -n | awk '/^0.0.0.0/ { print $5 " " $NF }' | sort | awk '{ print $NF; exit }') DEFAULT_ROUTE_DEV=$(route -n | awk '/^0.0.0.0/ { print $5 " " $NF }' | sort | awk '{ print $NF; exit }')
sudo iptables -t nat -A POSTROUTING -o ${DEFAULT_ROUTE_DEV} -s ${OSH_EXT_SUBNET} -j MASQUERADE sudo iptables -t nat -A POSTROUTING -o ${DEFAULT_ROUTE_DEV} -s ${OSH_EXT_SUBNET} -j MASQUERADE
container_id="$(sudo docker ps -f name=br-ex-dns-server -q -a)"
# NOTE(portdirect): Setup DNS for public endpoints # NOTE(portdirect): Setup DNS for public endpoints
sudo docker run -d \ if [ -z $container_id ]; then
sudo docker run -d \
--name br-ex-dns-server \ --name br-ex-dns-server \
--net host \ --net host \
--cap-add=NET_ADMIN \ --cap-add=NET_ADMIN \
@ -46,5 +49,8 @@ sudo docker run -d \
--resolv-file=/etc/kubernetes/kubelet-resolv.conf \ --resolv-file=/etc/kubernetes/kubelet-resolv.conf \
--address="/svc.cluster.local/${OSH_BR_EX_ADDR%/*}" \ --address="/svc.cluster.local/${OSH_BR_EX_ADDR%/*}" \
--listen-address="${OSH_BR_EX_ADDR%/*}" --listen-address="${OSH_BR_EX_ADDR%/*}"
else
echo "external bridge for dns already exists"
fi
sleep 1 sleep 1
sudo docker top br-ex-dns-server sudo docker top br-ex-dns-server