#!/bin/bash
\
all_cmii_name_space=(uavcloud-test uavcloud-feature uavcloud-dev uavcloud-devflight uavcloud-devoperation)
# shellcheck disable=SC2207


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 ""

  all_zero_replicas_deployment_list=($(kubectl get deployments -n "$name_space" -o=jsonpath='{.items[?(@.spec.replicas==0)].metadata.name}' | tr " " "\n"))

  for deployment_name in "${all_zero_replicas_deployment_list[@]}"; do
     if echo "$deployment_name" | grep -q "cmii"; then
       echo "[SCALE] - going to scale [$name_space] [$deployment_name] to 1 !!"
       kubectl scale deployment "$deployment_name" --replicas=1 -n "$name_space"
       echo ""
     fi
  done

  echo ""
done
