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")"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
[[ ! -r "$HOME/.kube/config" ]] \
|
||||
|| export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
|
||||
|
||||
if [[ -n "$(type -t 'k3s')" && -z "$(type -t 'kubectl')" ]]; then
|
||||
if [[ -r "${KUBECONFIG}" ]]; then
|
||||
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\"
|
||||
unset KUBECONFIG
|
||||
fi
|
||||
FIX_KUBECTL_RECALL=1 . \"$BASH_SOURCE\"
|
||||
FIX_KUBECTL_RECALL=1 . \"$SCRIPT_FULL_PATH\"
|
||||
}"
|
||||
fi
|
||||
fi
|
||||
|
@ -78,6 +80,7 @@ if [[ -z "${BASE_0}" || "${BASE_0}" == "$BASE_SHELL" ]]; then
|
|||
}
|
||||
fi
|
||||
elif [[ "$1" == '-' ]]; then
|
||||
printf "SCRIPT_FULL_PATH='%s'\n" "${BASH_SOURCE[0]}"
|
||||
cat "${BASH_SOURCE[0]}"
|
||||
else
|
||||
SCRIPT_NAME="$BASE_0"
|
||||
|
|
Loading…
Reference in New Issue