File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,17 @@ function list_clusters() {
3737# ## Switch cluster context
3838function switch_cluster() {
3939 # Verify it's a valid cluster name with kubectl
40- CLUSTER_NAME=$( kubectl config get-clusters | grep " $CLUSTER $" ) # Allow fuzzying on cluster name
41-
40+ CLUSTER_NAME=$( kubectl config get-clusters | grep " $CLUSTER $" )
4241 # Fallback in case the user has renamed their context for the cluster.
4342 if [ -z " ${CLUSTER_NAME} " ]; then
44- CLUSTER_NAME=$( kubectl config get-contexts -o name | grep $CLUSTER )
45- # If both lookups have failed, exit 1.
43+ # Allow fuzzying on context name
44+ CLUSTER_NAME=($( kubectl config get-contexts -o name | grep $CLUSTER ) )
45+ # If globbing gives more than one match, discard those and look for an exact match
46+ if [ ${# CLUSTER_NAME[@]} -ne 1 ]; then
47+ unset CLUSTER_NAME
48+ CLUSTER_NAME=$( kubectl config get-contexts -o name | grep $CLUSTER $)
49+ fi
50+ # If all lookups have failed, exit 1.
4651 if [ -z " ${CLUSTER_NAME} " ]; then
4752 RED=$( echo -en ' \033[00;31m' )
4853 YELLOW=$( echo -en ' \033[00;33m' )
You can’t perform that action at this time.
0 commit comments