Skip to content

Commit c9cf572

Browse files
committed
fix k8s context switch between clusters
1 parent 35a1897 commit c9cf572

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

tools/bash_aliases

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ alias switch='. /usr/local/bin/switch.sh'
3333
alias check-k8s='/usr/local/bin/check-k8s.sh'
3434
alias get-minio-token='kctx core-connectivity ; kubectl -n 60-minio-operator get secret $(kubectl -n 60-minio-operator get serviceaccount console-sa -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode'
3535
alias k='/usr/local/bin/kubectl'
36-
alias kctx='/usr/local/bin/kubectx'
36+
alias kctx='unset KUBECONFIG ; /usr/local/bin/kubectx'
37+
alias kubectx='unset KUBECONFIG ; /usr/local/bin/kubectx'
3738
alias kns='/usr/local/bin/kubens'
3839
alias kube-editor='. /usr/local/bin/kube-editor.sh'
3940
alias k9s-mode='. /usr/local/bin/k9s-mode.sh'

tools/k9s-run.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,12 @@ if [ -f ${K9S_CONFIG_FILE} ] ; then
4545
done
4646
fi
4747

48-
#--- Run k9s binary (defaut is read-only mode)
49-
k9s ${K9S_RUN_MODE}
48+
#--- Select current context to use for k9s session
49+
current_ctx="$(kubectx -c)"
50+
export KUBECONFIG="${HOME}/.kube/${current_ctx}.yml"
51+
if [ -s ${KUBECONFIG} ] ; then
52+
#--- Run k9s binary (defaut is read-only mode)
53+
k9s ${K9S_RUN_MODE}
54+
else
55+
printf "\n%bERROR : k8s context \"${KUBECONFIG}\" unknown.%b\n" "${RED}" "${STD}"
56+
fi

0 commit comments

Comments
 (0)