#!/bin/bash

app_list_backend=("cmii-uav-user" "cmii-admin-data" "cmii-admin-user" "cmii-uav-airspace" "cmii-uav-brain" "cmii-uav-clusters" "cmii-uav-data-post-process" "cmii-uav-developer" "cmii-uav-device" "cmii-uav-kpi-monitor" "cmii-uav-live" "cmii-uav-logger" "cmii-uav-mission" "cmii-uav-monitor" "cmii-uav-mqtthandler" "cmii-uav-notice" "cmii-uav-oauth" "cmii-uav-process" "cmii-uav-surveillance" "cmii-uav-user" "cmii-uav-waypoint" "cmii-uav-material-warehouse" "cmii-uav-gateway" "cmii-open-gateway" "cmii-admin-gateway")

app_list_frontend=("cmii-uav-platform" "cmii-uav-platform-ai-brain" "cmii-uav-platform-hyperspectral" "cmii-uav-platform-mws" "cmii-uav-platform-mws-admin" "cmii-uav-platform-oms" "cmii-uav-platform-cms" "cmii-uav-platform-open" "cmii-uav-platform-splice")

for app in ${app_list_frontend[@]}; do
    echo ${app}
    echo "--------------------------------------------------------------"
    echo ""
    echo  "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"$app\",\"image\":\"harbor-manager.sre.cdcyy.cn/cmii/$app:2.1.14\"}]}}}}"
    echo "--------------------------------------------------------------"
    echo ""

    kubectl patch deployment $(kubectl get deployment -n cmii | grep -w "${app}" | awk '{print $1}') -n cmii -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"$app\",\"image\":\"harbor-manager.sre.cdcyy.cn/cmii/$app:2.1.14\"}]}}}}"
    echo "升级完成！！"
    echo ""
done

kubectl get deployment -n uavcloud-dev | grep cmii-uav-user | awk '{print $1}'

kubectl patch deployment $(kubectl get deployment -n iot | grep mns | awk '{print $1}') -n iot -p '{"spec":{"template":{"spec":{"containers":[{"name": "iotx-foundry-mns","image":"docker.io/csiot/iotx-foundry-mns:latest"}]}}}}'

kk delete ing -n uavcloud-dev $(kk get ing -n uavcloud-dev | grep cmii | awk '{print$1}')

kk delete configmap -n uavcloud-dev $(kk get configmap -n uavcloud-dev | grep tenant-prefix | awk '{print$1}')
