#!/bin/bash


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


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


for kindof in deployments service
do
  # kubectl -n ${nameSpace} get $kindof | grep "cmii" | grep -v "hyperspectral" | grep -v "rtsp" | grep -v "mysql"| grep -v "cms" | grep -v "minio" | awk '{print$1}'
  kubectl -n ${nameSpace} delete $kindof $(kubectl -n ${nameSpace} get $kindof | grep "cmii" | grep -v "hyperspectral" |  grep -v "rtsp" | grep -v "mysql" | grep -v "cms" | grep -v "minio" | 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  ingress
do
  kubectl -n ${nameSpace} delete $kindof $(kubectl -n ${nameSpace} get $kindof | grep -v "cms" | grep -v "minio"|  grep -v "srs" |  grep -v "vms"|  grep -v "yj" | awk '{print$1}')
done


kubectl -n ${nameSpace} delete pvc

for host in d{1..9}; do
    echo "${host}"

    ssh ${host} "yum install -y chrony && systemctl enable chronyd && systemctl start chronyd"
    ssh ${host} "sed -i \"s/server 0.centos.pool.ntp.org iburst/server 192.168.11.170 minpoll 4 maxpoll 10 iburst/g\" /etc/chrony.conf && systemctl restart chronyd"

    echo "开始等待"
    sleep 8

    ssh ${host} "chronyc -n sources -v && chronyc tracking"


    echo "---------------------------------------"

done





for image in $(docker image ls | grep cmii | grep "platform" |grep 4.0.0 | awk '{print$3}') ;
#for image in $(docker image ls | grep rancher | awk '{print$3}') ;
do

  echo ${iamimagege}

  json=$(docker inspect ${image})

  echo $json | grep  "RepoTags" -A2 >> 1.txt
  echo $json | grep "Id"  >> 1.txt
  echo ""  >> 1.txt
  echo "-------------------------------------" >> 1.txt

done

for image in $(docker image ls | grep cmii |grep 4.0.0 | awk '{print$3}') ;
#for image in $(docker image ls | grep rancher | awk '{print$3}') ;
do

  echo ${image}
  docker image rmi ${image}

done