#!/bin/bash
ROOT=${ROOT:-.} 
if [ -r "$ROOT/ssl/fullchain.pem" ] ; then 
   if [ -x "$ROOT/make_istio-system_secret.sh" ] ; then 
      $ROOT/make_istio-system_secret.sh $ROOT/ssl
   else
      kubectl delete secret web-certs -n cloudnative-zone 2>/dev/null
      kubectl create secret tls web-certs --cert=$ROOT/ssl/fullchain.pem --key=$ROOT/ssl/privkey.pem -n cloudnative-zone
  fi
  if [ ! -r "$ROOT/ssl/fullchain.pem" ] ; then 
     echo "No SSL certificate" 
     exit  
  fi 
fi
echo "checking configMaps ..." 
kubectl delete -f $ROOT/configMap-etc.yaml 2>/dev/null
kubectl apply -f $ROOT/configMap-etc.yaml 

kubectl delete -f $ROOT/web.yaml 2>/dev/null 
kubectl delete -f $ROOT/srvc-web.yaml 2>/dev/null 
kubectl delete -f $ROOT/prxy-virtual-srvc-web.yaml 2>/dev/null 
kubectl delete -f $ROOT/prxy-gateway-web.yaml 2>/dev/null 

kubectl apply -f $ROOT/srvc-web.yaml
kubectl apply -f $ROOT/prxy-virtual-srvc-web.yaml
kubectl apply -f $ROOT/prxy-gateway-web.yaml
kubectl apply -f $ROOT/web.yaml

#echo "web.cloudnative-zone reload ..." 
#curl -s -o /dev/null -I -w "%{http_code}" https://web.cloudnative.zone
echo "__oOo__________oOo__________oOo__" 
