Skip to content

Commit

Permalink
fix k8s context switch between clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Jul 1, 2024
1 parent 35a1897 commit c9cf572
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tools/bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ alias switch='. /usr/local/bin/switch.sh'
alias check-k8s='/usr/local/bin/check-k8s.sh'
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'
alias k='/usr/local/bin/kubectl'
alias kctx='/usr/local/bin/kubectx'
alias kctx='unset KUBECONFIG ; /usr/local/bin/kubectx'
alias kubectx='unset KUBECONFIG ; /usr/local/bin/kubectx'
alias kns='/usr/local/bin/kubens'
alias kube-editor='. /usr/local/bin/kube-editor.sh'
alias k9s-mode='. /usr/local/bin/k9s-mode.sh'
Expand Down
11 changes: 9 additions & 2 deletions tools/k9s-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ if [ -f ${K9S_CONFIG_FILE} ] ; then
done
fi

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

0 comments on commit c9cf572

Please sign in to comment.