mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
Add kube context manager
This commit is contained in:
parent
c3b072eace
commit
bfeba55509
2 changed files with 37 additions and 0 deletions
14
plugins/kube/README.md
Normal file
14
plugins/kube/README.md
Normal file
|
|
@ -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
|
||||
```
|
||||
23
plugins/kube/kube.plugin.zsh
Normal file
23
plugins/kube/kube.plugin.zsh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export KUBE_HOME=~/.kube
|
||||
|
||||
function kgp {
|
||||
echo $KUBECONFIG
|
||||
}
|
||||
|
||||
function ksp {
|
||||
local rprompt=${RPROMPT/<aws:$(kgp)>/}
|
||||
|
||||
export KUBE_PROFILE=$1
|
||||
export KUBECONFIG=$KUBE_HOME/$1-config
|
||||
|
||||
export RPROMPT="<kube:$KUBE_PROFILE>$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
|
||||
Loading…
Add table
Add a link
Reference in a new issue