dotfiles/.functions/kubernetes.sh
Jonas Forsberg 46b51d5017
.
2021-11-12 13:34:58 +01:00

36 lines
1.0 KiB
Bash

#!/bin/bash
function kubernetes_configs(){
# set KUBECONFIG to default kubeconfig and all *.yaml files in .kube
local KUBE_CONFIG_DEFAULT="$HOME/.kube/config"
local KUBE_CONFIG_DIR="$HOME/.kube"
local KUBE_CONFIG_EXTENTION="*.yaml"
if [[ -f "${KUBE_CONFIG_DEFAULT}" ]];then
export KUBECONFIG="$KUBE_CONFIG_DEFAULT"
fi
[[ -d "${KUBE_CONFIG_DIR}" ]] || mkdir -p "${KUBE_CONFIG_DIR}"
# shellcheck disable=SC2044
for file in $(find "${KUBE_CONFIG_DIR}" -type f -name "$KUBE_CONFIG_EXTENTION"); do
export KUBECONFIG="$file:$KUBECONFIG"
done
if [[ $(command -v kubectl) ]];then
complete -W "$(kubectl config get-contexts -o name)" kuc
fi
}
kubernetes_configs
function kc(){
# print all kubernetes contexts
kubectl config get-contexts
}
function kuc(){
# use kubernetes context <param>
kubectl config use-context "$1"
}
function k(){
kubectl "$@"
}
[[ $(type -t __start_kubectl) == function ]] && complete -o default -F __start_kubectl k