Fix: fix-kubectl failed to detect local .kube/config
This commit is contained in:
parent
fc9a93c2bc
commit
270eb99510
13
fix-kubectl
13
fix-kubectl
|
@ -3,7 +3,12 @@ BASE_0="$(basename ${0#-})"
|
||||||
BASE_SHELL="$(basename "$SHELL")"
|
BASE_SHELL="$(basename "$SHELL")"
|
||||||
if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
|
|
||||||
if [[ -z "FIX_KUBECTL_RECALL" ]]; then
|
[[ -n "$KUBECONFIG" && -r "$KUBECONFIG" ]] || unset KUBECONFIG
|
||||||
|
|
||||||
|
[[ ! -r "$HOME/.kube/config" ]] \
|
||||||
|
|| export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
|
||||||
|
|
||||||
|
if [[ -z "$KUBECONFIG" && -z "$FIX_KUBECTL_RECALL" ]]; then
|
||||||
unset kubectl 2>/dev/null || unalias kubectl 2>/dev/null || true
|
unset kubectl 2>/dev/null || unalias kubectl 2>/dev/null || true
|
||||||
|
|
||||||
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
||||||
|
@ -11,9 +16,6 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
|
|
||||||
[[ 'function' == $(type -t kubectl-fix) ]] && unset kubectl-fix
|
[[ 'function' == $(type -t kubectl-fix) ]] && unset kubectl-fix
|
||||||
|
|
||||||
[[ ! -r "$HOME/.kube/config" ]] \
|
|
||||||
|| export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
|
|
||||||
|
|
||||||
if [[ -n "$(type -t 'k3s')" && -z "$(type -t 'kubectl')" ]]; then
|
if [[ -n "$(type -t 'k3s')" && -z "$(type -t 'kubectl')" ]]; then
|
||||||
if [[ -r "${KUBECONFIG}" ]]; then
|
if [[ -r "${KUBECONFIG}" ]]; then
|
||||||
kubectl() { k3s kubectl "${@}"; }
|
kubectl() { k3s kubectl "${@}"; }
|
||||||
|
@ -25,7 +27,7 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
sudo install --mod 600 --owner \"$USER\" \"\${KUBECONFIG}\" \"$HOME/.kube/config\"
|
sudo install --mod 600 --owner \"$USER\" \"\${KUBECONFIG}\" \"$HOME/.kube/config\"
|
||||||
unset KUBECONFIG
|
unset KUBECONFIG
|
||||||
fi
|
fi
|
||||||
FIX_KUBECTL_RECALL=1 . \"$BASH_SOURCE\"
|
FIX_KUBECTL_RECALL=1 . \"$SCRIPT_FULL_PATH\"
|
||||||
}"
|
}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -78,6 +80,7 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
elif [[ "$1" == '-' ]]; then
|
elif [[ "$1" == '-' ]]; then
|
||||||
|
printf "SCRIPT_FULL_PATH='%s'\n" "${BASH_SOURCE[0]}"
|
||||||
cat "${BASH_SOURCE[0]}"
|
cat "${BASH_SOURCE[0]}"
|
||||||
else
|
else
|
||||||
SCRIPT_NAME="$BASE_0"
|
SCRIPT_NAME="$BASE_0"
|
||||||
|
|
Loading…
Reference in New Issue