#!/bin/bash


#all_cmii_name_space=(uavcloud-test uavcloud-feature uavcloud-uat uavcloud-dev uavcloud-devflight uavcloud-devoperation)
all_cmii_name_space=(uavcloud-test uavcloud-feature uavcloud-dev uavcloud-devflight uavcloud-devoperation)

echo ""
for name_space in "${all_cmii_name_space[@]}"; do
  echo "[NAMESPACE] - start to deal with namespace [$name_space]"
  if ! kubectl get ns "$name_space"; then
      echo "[NAMESPACE] - namespace of [$name_space] not exists !"
      echo ""
      continue
  fi
  echo ""

  kubectl get pods --namespace="${name_space}" --sort-by='.status.containerStatuses[].restartCount' | awk '$4 > 30  {print $1} ' | sed 's/-[a-z0-9]\{9,10\}-[a-z0-9]\{5\}$//' | xargs -I {} kubectl scale -n "${name_space}" --replicas=0 deployment {}
  echo ""

done
