initial commit
This commit is contained in:
commit
1ba9111b3c
2 changed files with 49 additions and 0 deletions
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# ktx
|
48
ktx
Normal file
48
ktx
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
CUR_FILE="$HOME/.kube/current"
|
||||||
|
|
||||||
|
|
||||||
|
# Switch context
|
||||||
|
# Usage: ktx <cluster> [namespace]
|
||||||
|
ktx() {
|
||||||
|
unset KUBECONFIG
|
||||||
|
CONTEXT=${1:-}
|
||||||
|
NAMESPACE=${2:-}
|
||||||
|
|
||||||
|
if [ -z $CONTEXT ]; then
|
||||||
|
SELECTION=$(kubectl config get-contexts | awk '{print $2"|"$4}' | tail +2 | fzf)
|
||||||
|
CONTEXT=$(echo $SELECTION | cut -d"|" -f1)
|
||||||
|
DEFAULT_NS=$(echo $SELECTION | cut -d"|" -f2)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z $NAMESPACE ]; then
|
||||||
|
NAMESPACE=${DEFAULT_NS}
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILENAME="$HOME/.kube/frickel/${CONTEXT}_${NAMESPACE}.conf"
|
||||||
|
|
||||||
|
kubectl config view --minify --flatten --context $CONTEXT > ${FILENAME}
|
||||||
|
|
||||||
|
export KUBECONFIG=${FILENAME}
|
||||||
|
|
||||||
|
kubectl config set-context --current --namespace=$NAMESPACE
|
||||||
|
|
||||||
|
ln -sf ${FILENAME} ${CUR_FILE}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Switch namespace
|
||||||
|
# Usage: kn [namespace]
|
||||||
|
kn() {
|
||||||
|
NAMESPACE=${1:-}
|
||||||
|
|
||||||
|
if [ -z $NAMESPACE ]; then
|
||||||
|
NAMESPACE=$(kubectl get namespace | awk '{ print $1 }' | tail +2 | fzf)
|
||||||
|
fi
|
||||||
|
|
||||||
|
kubectl config set-context --current --namespace=$NAMESPACE
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -f ${CUR_FILE} ]; then
|
||||||
|
export KUBECONFIG=$(readlink -f "${CUR_FILE}")
|
||||||
|
fi
|
Loading…
Add table
Add a link
Reference in a new issue