Skip to content

Instantly share code, notes, and snippets.

@edsonmarquezani
Created June 3, 2019 12:59
Show Gist options
  • Save edsonmarquezani/02c10fa5f4c85ee5735aeee0349b41df to your computer and use it in GitHub Desktop.
Save edsonmarquezani/02c10fa5f4c85ee5735aeee0349b41df to your computer and use it in GitHub Desktop.
kubectl-set-cluster() {
local cluster=""
local options=""
local red='\033[0;31m'
local nc='\033[0m'
if [ $# -gt 0 ]; then
cluster=$1
else
for context in $(kubectl config get-contexts | tr -d '*' | tail -n +2 | awk '{print $1}' | sort); do
options="${options} ${context} ''"
done
cluster=$(dialog --stdout --menu 'Choose Kubernetes Cluster' 0 0 0 ${options})
clear
fi
kubectl config use-context $cluster >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${red}cluster ${cluster} not found${nc}"
else
echo "cluster ${cluster} set"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment