#!/usr/bin/bash

#./restartPod.sh test 8 3m
#epmapp/epmprod
#ENV=$1
#CONCURRENCY=$2
#SLEP_TIME=$3

POD_LIST=`kubectl -n $ENV get po | tail -n+2 | awk '{print $1}'`
echo "system ENV: ${ENV}, pod list: ${POD_LIST[@]}"

i=0
for pod in ${POD_LIST[@]}
do
  if [[ $pod =~ "epm-ingress-nginx-controller" ]]; then
    echo 'skip sys pod'
  else
    echo "restarting $pod"
    kubectl -n ${ENV} delete po $pod

    i=`expr $i + 1`
    echo $i
    val=`expr $i % $CONCURRENCY`
    if [ $val = 0 ]
    then
          echo "sleep $SLEP_TIME,waiting for pod ready"
          sleep $SLEP_TIME
    fi
  fi 
done