Direnv support
hinricht opened this issue · 5 comments
Hi,
I'm currently using direnv to automatically set the kubeconfig context when entering a directory. This works by exporting KUBECONFIG
with direnv.
However, afaik this is not possible with kubeswitch because kubeswitch generates tmp config files like ~/.kube/.switch_tmp/config.1692710140.tmp
which don't contain the context name (and are eventually garbage collected ?). It would be nice if kubeswitch would create/update kubeconfig files including at least the name of the context and can be used permanently.
I wonder if such feature is in the scope of kubeswitch.
This is how other projects relate to this issue:
- kubesess i.e. uses
KUBECONFIG=~/.kube/kubesess/cache/mastodon-dev:/home/varac/.kube/config
but don't have hook support - kubie has a pending PR which adds an export function that can get used with direnv
Hi, you might be able to use the underlying switcher
binary that returns the location of the created tmp file. In the normal setup, the sourced switch.sh
script would then export the KUBECONFIG env variable.
switcher dev-shoot-core-i500101-aws/garden-core--i500101-aws-external
/Users/d060239/.kube/.switch_tmp/config.3503431468.tmp
in your .envrc
:
CONTEXT="my-cluster"
export KUBECONFIG=$(switcher --config-path <my-switch-config-path> $CONTEXT)
Awesome, thanks !
So I tried this, but the behavior of switcher
changed, and it now outputs a prefix, and the context too.
I tried this:
export KUBECONFIG=$(switcher kind-kind | tr -d '__ ' | cut -d, -f1)
But it didn't work as expected, $KUBECONFIG
gets set to the tmp file, but it doesn't exist when I try to cat $KUBECONFIG
.
@danielfoehrKn any tips?
I can second this, I have the same issue. @danielfoehrKn are you aware of this ?