Last active
November 28, 2024 07:27
-
-
Save marinho/44f8cc3aa1f5fd949daf8be2054b6261 to your computer and use it in GitHub Desktop.
Fish scripts to set kubectl and k9s to use kubeconfig from current directory
This file contains hidden or 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
function find-kubeconfig | |
set dir (pwd) | |
while true | |
if test -d "$dir/.kube" | |
echo "$dir/.kube" | |
return | |
end | |
if test "$dir" = "/" | |
break | |
end | |
set dir (dirname $dir) | |
end | |
# Return nothing if no kubeconfig.yaml is found | |
echo "" | |
end |
This file contains hidden or 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
function k9s | |
set kubedir (find-kubeconfig) | |
set kubeconfig "$kubedir/config" | |
if test -n "$kubeconfig" | |
set KUBECONFIG $kubeconfig | |
end | |
command k9s $argv | |
end |
This file contains hidden or 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
function kubectl | |
set kubedir (find-kubeconfig) | |
set kubeconfig "$kubedir/config" | |
set kubecache "$kubedir/cache" | |
if test -n "$kubeconfig" | |
set KUBECONFIG $kubeconfig | |
command kubectl $argv --cache-dir="$kubecache" | |
else | |
command kubectl $argv | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment