#!/usr/bin/env bash
# 文件: ingress.sh

source $(realpath -m ..)/.vars.conf

set -o pipefail

# 安装 Ingress 组件
if [[ "${ingress_name}" == "istio" ]]
then

    printf "$info: [ ${bldgre}istio${txtrst} ] 安装中...\n"
    
    # 安装 icstioctl
    /bin/bash ../files/istioctl-${istio_version:-1.19.10}.bin
    
    istioctl install -y --set meshConfig.accessLogFile=/dev/stdout  \
                        --set profile=default \
                        --set hub=${image_registry} \
                        --set tag="${istio_version:-1.19.10}"

    #istioctl upgrade -y --set meshConfig.accessLogFile=/dev/stdout  \
    #                    --set profile=default \
    #                    --set hub=${image_registry} \
    #                    --set tag="${istio_version}" \
    #                    --set values.pilot.autoscaleEnabled=false \
    #                    --set values.gateways.istio-ingressgateway.autoscaleEnabled=false \
    #                    --set values.pilot.replicaCount=2 \
    #                    --set values.gateways.istio-ingressgateway.replicaCount=2 \
    #                    #--set values.global.imagePullSecrets[0]=gitee-hub
    
    # 更新SVC类型
    kubectl -n istio-system wait --for=condition=ready pod -l app=istio-ingressgateway --timeout=45s &&  kubectl -n istio-system patch svc istio-ingressgateway -p '{"spec": {"ports": [{"nodePort": 443, "port": 443,"targetPort": 8443,"name": "https"},{"nodePort": 80, "port": 80,"targetPort": 8080,"name": "http2"}],"type": "NodePort"}}'
    #kubectl -n istio-system rollout status deploy/istio-ingressgateway -w &&  kubectl -n istio-system patch svc istio-ingressgateway -p '{"spec": {"ports": [{"nodePort": 443, "port": 443,"targetPort": 8443,"name": "https"},{"nodePort": 80, "port": 80,"targetPort": 8080,"name": "http2"}],"type": "NodePort"}}'
fi 
