From bfeba5550919c6e016e49c06090acc0d1dafd4b0 Mon Sep 17 00:00:00 2001 From: drymer Date: Tue, 26 Dec 2017 14:11:16 +0100 Subject: [PATCH] Add kube context manager --- plugins/kube/README.md | 14 ++++++++++++++ plugins/kube/kube.plugin.zsh | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 plugins/kube/README.md create mode 100644 plugins/kube/kube.plugin.zsh diff --git a/plugins/kube/README.md b/plugins/kube/README.md new file mode 100644 index 000000000..fed930b8b --- /dev/null +++ b/plugins/kube/README.md @@ -0,0 +1,14 @@ +# Kubectl context manager +Kubectl, the kubernetes client, needs context to work correctly. By default, it uses the file on `~/.kube/config`, which has an horrible design. With this plugin, the better approach is to not have a `~/.kube/config` file and `n` `~/.kube/something-config`. If you do so, you'll be able to manage multiple contexts easily. + +This plugin is based on the [aws](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#aws) one. The functions that provides are `ksp` and `kgp`. The first one let's you choose between the contexts and the second one shows which one is being used. + +See the `~/.kube` directory: + +```bash +tree ~/.kube + +/home/whatever/.kube +├── firstContext-config +└── secondContext-config +``` diff --git a/plugins/kube/kube.plugin.zsh b/plugins/kube/kube.plugin.zsh new file mode 100644 index 000000000..72847cba5 --- /dev/null +++ b/plugins/kube/kube.plugin.zsh @@ -0,0 +1,23 @@ +export KUBE_HOME=~/.kube + +function kgp { + echo $KUBECONFIG +} + +function ksp { + local rprompt=${RPROMPT//} + + export KUBE_PROFILE=$1 + export KUBECONFIG=$KUBE_HOME/$1-config + + export RPROMPT="$rprompt" +} + +function kube_profiles { + reply=($(ls $KUBE_HOME/*-config | + awk -F'/' '{print $5}' | + sed "s/-config$/ /g" | + tr -d '\n')) +} + +compctl -K kube_profiles ksp