Skip to content

Instantly share code, notes, and snippets.

@Aceeri
Created May 18, 2018 22:25
Show Gist options
  • Select an option

  • Save Aceeri/2c07e03d9eea9d1b416affb50b07e5c8 to your computer and use it in GitHub Desktop.

Select an option

Save Aceeri/2c07e03d9eea9d1b416affb50b07e5c8 to your computer and use it in GitHub Desktop.
watched=()
pids=()
contains() {
local value=$1;
for pod in "${watched[@]}"
do
if [[ $pod == $value ]]
then
echo "1"
fi
done
echo "0"
}
STOP=false
terminate() {
echo "Stopping";
STOP=true
for pid in ${pids[@]}
do
kill -9 $pid || true
done
}
trap "terminate" SIGTERM SIGKILL
while [[ $STOP == "false" ]]
do
pods='\n' read -r -a array <<< $(kubectl get pods -l app=$1 -o name | sed 's/pods\///g')
for pod in "${array[@]}"
do
if [[ $(contains $pod) == 0 && $(kubectl get pod $pod | rg "Running" | rg "1/1") ]]
then
cat <(kubectl logs $pod -f --tail 500) & pids+=($!)
echo "Following $pod"
watched+=($pod)
fi
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment