#!/bin/bash

set -o errexit
set -o pipefail

if [ $# -ne 5 ]
then
    echo "Usage: $0 <k8s> <env> <region> <image> <role>"
    echo
    echo "Available k8s: eks, gke"
    echo "Available env: dev, staging, prod"
    echo "Available regions: it can be region like us-west-2 for aws or us-west1 for gcp"
    echo "Available images: the image name available in ecr or gcr"
#    echo "Available sli images: the sli image name available in ecr or gcr"
    exit
fi

K8S=$1
ENV=$2
REGION=$3
IMAGE=$4
ROLE=$5


echo "deploy service account start"
sed -i "s|{role}|${ROLE}|g" ./sa_${K8S}.yaml
kubectl apply -f ./sa_${K8S}.yaml
echo "deploy service acccount end"


echo "deploy test start"
cp ./deployment-template.yaml ./region-deploy-test_${K8S}.yaml
sed -i "s|{image}|${IMAGE}|g" ./region-deploy-test_${K8S}.yaml
kubectl apply -f ./region-deploy-test_${K8S}.yaml
echo "deploy test end"

echo "deploy svc start"
kubectl apply -f ./svc_${K8S}.yaml
echo "deploy svc end"

echo "deploy service monitor start"
kubectl apply -f  ./service_monitor_${K8S}.yaml
echo "deploy service monitor end"

echo "apply rules start"
kubectl apply -f  ./rules/demo.yaml
echo "apply rules end"
