#!/usr/bin/env bash

## Process command line flags ##

source ${SCRIPTS_DIR}/lib/shflags
DEFINE_string 'restart' 'all' "Which pods to restart: none, all, gateway, routeagent, globalnet"
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/submariner-gateway
import_image quay.io/submariner/submariner-route-agent
import_image quay.io/submariner/submariner-globalnet
import_image quay.io/submariner/submariner-networkplugin-syncer

declare_kubeconfig

case "${restart}" in
	gateway|routeagent|globalnet|networkplugin-syncer)
		run_subm_clusters reload_pods daemonset submariner-${restart}
		;;
	all)
		run_subm_clusters reload_pods daemonset submariner-gateway
		run_subm_clusters reload_pods daemonset submariner-routeagent
		run_subm_clusters reload_pods deployment submariner-networkplugin-syncer
		run_subm_clusters reload_pods daemonset submariner-globalnet || true # globalnet is not always enabled
		;;
	none)
		;;
	*)
		echo "restart must be one of: none, gateway, routeagent, globalnet or all (default)"
		exit 1
		;;
esac
