github.com/imran-kn/cilium-fork@v1.6.9/contrib/policy-watcher/cilium-policy-watcher (about) 1 #!/bin/bash 2 3 set -e 4 5 if [ -z "$1" -o "$1" = "REPO" ]; then 6 echo "Usage: policy-watcher.sh REPOSITORY" 7 exit 1 8 fi 9 10 POLL_DELAY=1 11 POLICY_REPO=$1 12 CACHE_REPO=./policy-cache 13 POLICY_TOOL=cilium-net-policy 14 15 cd /var/run/cilium 16 17 ret=0 18 which ${POLICY_TOOL} > /dev/null 2>&1 || ret=$? 19 if [ $ret -ne 0 ]; then 20 echo "No policy tool found, install cilium-net-policy" 21 exit 1 22 fi 23 24 while true; do 25 rm -fr $CACHE_REPO 2> /dev/null || true 26 27 git clone --recursive "$POLICY_REPO" $CACHE_REPO 28 cd $CACHE_REPO 29 30 # Wait for incremental updates 31 cp /usr/lib/cilium/githooks/post-merge .git/hooks/ 32 33 # Initial import 34 cilium-net-policy import -p . || true 35 36 while true; do 37 sleep $POLL_DELAY 38 ret=0 39 git pull -q --recurse-submodules=yes || ret=$? 40 if [ $ret -ne 0 ]; then 41 break 42 fi 43 44 ret=0 45 git submodule update || ret=$? 46 if [ $ret -ne 0 ]; then 47 break 48 fi 49 done 50 done