#!/usr/bin/env bash
set -euo pipefail

./select_target.sh "$@"

echo "Deactivating frontend"
kubectl scale --replicas=0 deployment/frontend

sleep_duration=${2:-30}
echo "Sleep ${sleep_duration}"
sleep ${sleep_duration}

./cache_cli.sh "$1" "FLUSHALL"
echo "Cache cleared"

echo "Reactivating frontend"
kubectl scale --replicas=1 deployment/frontend

kubectl wait --for=condition=available --timeout=600s deployment/frontend

echo "Success"
