Created
June 3, 2019 12:59
-
-
Save edsonmarquezani/02c10fa5f4c85ee5735aeee0349b41df to your computer and use it in GitHub Desktop.
This file contains 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 characters
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