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,19 +32,25 @@ 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
--name br-ex-dns-server \ sudo docker run -d \
--net host \ --name br-ex-dns-server \
--cap-add=NET_ADMIN \ --net host \
--volume /etc/kubernetes/kubelet-resolv.conf:/etc/kubernetes/kubelet-resolv.conf:ro \ --cap-add=NET_ADMIN \
--entrypoint dnsmasq \ --volume /etc/kubernetes/kubelet-resolv.conf:/etc/kubernetes/kubelet-resolv.conf:ro \
${DNSMASQ_IMAGE} \ --entrypoint dnsmasq \
--keep-in-foreground \ ${DNSMASQ_IMAGE} \
--no-hosts \ --keep-in-foreground \
--bind-interfaces \ --no-hosts \
--resolv-file=/etc/kubernetes/kubelet-resolv.conf \ --bind-interfaces \
--address="/svc.cluster.local/${OSH_BR_EX_ADDR%/*}" \ --resolv-file=/etc/kubernetes/kubelet-resolv.conf \
--listen-address="${OSH_BR_EX_ADDR%/*}" --address="/svc.cluster.local/${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