Created
June 10, 2018 20:09
-
-
Save ralucas/e1aa1af291d463804acdf76d7edc194f to your computer and use it in GitHub Desktop.
Revisions
-
ralucas created this gist
Jun 10, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/bin/bash -e APP=$1 ENV=$2 if [ -z "$APP" ] || [ -z "$ENV" ]; then echo -e "Missing parameters\n\nUsage:\n\tswitch_kubectl [app_name] [environment]" exit 0 fi if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then echo -e "Usage:\n\tswitch_kubectl [app_name] [environment]" exit 0 fi RED=`tput setaf 1` GREEN=`tput setaf 2` RESET=`tput sgr0` CONTEXT=`kubectl config view | grep "${APP}-${ENV}" -m 1 | sed -E "s/[[:space:]]+name\:[[:space:]]//"` echo "Using ${CONTEXT}" SWITCHED_CONTEXT=`kubectl config use-context ${CONTEXT}` echo $SWITCHED_CONTEXT SC=`echo ${SWITCHED_CONTEXT} | grep -o "${CONTEXT}"` if [ "${SC}" != "${CONTEXT}" ]; then echo "Bad kubectl context!" else echo "Successfully switched kubernetes to application [ ${RED}${APP}${RESET} ] on [ ${GREEN}${ENV}${RESET} ]" fi