#!/usr/bin/env bash

## Process command line flags ##

source ${SCRIPTS_DIR}/lib/shflags
DEFINE_string 'restart' 'all' "Which lighthouse pods to restart: none, all, agent, coredns"
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

restart="${FLAGS_restart}"

echo "Running with: restart=${restart}"

set -em

source ${SCRIPTS_DIR}/lib/debug_functions
source ${SCRIPTS_DIR}/lib/deploy_funcs
source ${SCRIPTS_DIR}/lib/utils
source ${SCRIPTS_DIR}/lib/cluster_settings
source ${DAPPER_SOURCE}/scripts/cluster_settings

import_image quay.io/submariner/lighthouse-agent
import_image quay.io/submariner/lighthouse-coredns

declare_kubeconfig

case "${restart}" in
	agent|coredns)
		run_subm_clusters reload_pods deployment submariner-lighthouse-${restart}
		;;
	all)
		run_subm_clusters reload_pods deployment submariner-lighthouse-agent
		run_subm_clusters reload_pods deployment submariner-lighthouse-coredns
		;;
	none)
		;;
	*)
		echo "restart must be one of: none, agent, coredns or all (default)"
		exit 1
		;;
esac
