#!/bin/bash

# 清除所有没有正常运行的pod
export namespace=xmyd
kubectl delete pod --namespace=${namespace} $(kubectl get pod --no-headers=true --namespace=${namespace} | awk '$4!="Running"{print $1}')

export nameSpace="uavcloud-demo"
kubectl -n ${nameSpace} delete configmap nginx-cm default-nginx-cm


## 删除所有的deployment和service
export nameSpace="uavcloud-demo"

for kindof in deployment service
do
  # kubectl -n ${nameSpace} get $kindof | grep "cmii" | grep -v "hyperspectral" |  grep -v "rtsp" | grep -v "clusters" | grep -v "mysql"  | grep -v "minio"| grep -v "srs"|  grep -v "autowaypoint" | awk '{print$1}'
  kubectl -n ${nameSpace} delete $kindof $(kubectl -n ${nameSpace} get $kindof | grep "cmii" | grep -v "hyperspectral" |  grep -v "rtsp" | grep -v "clusters" | grep -v "mysql"  | grep -v "minio"| grep -v "srs" | awk '{print$1}')
done



##
for kindof in configmap
do
  kubectl -n ${nameSpace} delete $kindof $(kubectl -n ${nameSpace} get $kindof | grep "tenant" | grep -v "cms" | grep -v "minio"|  grep -v "srs" |  grep -v "vms"|  grep -v "yj" | awk '{print$1}')
done


for kindof in  pods
do
  kubectl -n zhbf delete $kindof $(kubectl -n zhbf get $kindof | grep "cmii-uav"| awk '{print$1}')
done


kubectl -n ${nameSpace} delete pvc

kubectl patch pvc -n uavcloud-dev glusterfs-backend-log-pvc -p '{"metadata":{"finalizers":null}}'


# 获取所有的image的名称
export nameSpace="uavcloud-demo"

for deployment in $(kubectl get deployments -n $nameSpace -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
do
#  echo "当前deployment为 => $deployment"
  kubectl get deployment $deployment -n $nameSpace  -o=jsonpath='{.spec.template.spec.containers[*].image}'
  echo ""
done



