Created
June 10, 2021 04:40
-
-
Save aita/67409f0bf15770addbeef874850506f8 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
#!/usr/bin/env bash | |
kubenv () { | |
if [[ -z "$1" ]]; then | |
cat <<EOF >/dev/stderr | |
Usage: kubenv CONTEXT_NAME | |
EOF | |
return 1 | |
fi | |
local -r ctx="$1" | |
local -r ctxfile=$(mktemp) | |
cat <<EOF >$ctxfile | |
apiVersion: v1 | |
kind: Config | |
current-context: ${ctx} | |
EOF | |
if [[ ${KUBECONFIG_SAVED+x} ]]; then | |
export KUBECONFIG_SAVED=$KUBECONFIG | |
fi | |
KUBECONFIG=$KUBECONFIG_SAVED | |
if [[ -z "$KUBECONFIG" ]]; then | |
KUBECONFIG="${XDG_CACHE_HOME:-$HOME/.kube}/config" | |
fi | |
KUBECONFIG="$ctxfile:$KUBECONFIG" | |
export KUBECONFIG | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment