kubeswitch icon indicating copy to clipboard operation
kubeswitch copied to clipboard

ability to expose kubeswitch context

Open fenio opened this issue 10 months ago • 1 comments

Hello,

First of all thanks for this lovely project. It's a life changer for me.

But I'd love to make it even more lovely for my personal needs and for that I need ability to somehow rename k8s context based on information from kubeswitch and its context.

switch list-contexts shows something like this:

us-ord-alpha/lke236266-ctx
us-ord-beta/lke236267-ctx

These us-ord-xxx are let's say userfriendly names of my clusters while lkeXXXXX is actual context name listed in kubeconfig. So relevant part of kubeconfig looks like this:

current-context: lke236266-ctx
kubeswitch-context: us-ord-alpha/lke236266-ctx

I'd like to get "us-ord-alpha" into my shell prompt somehow but that information is not exposed so currently if I switch to "us-ord-alpha" I'm getting the following in my prompt:

[☸ lke236266:default] ❯ ~

I'm looking for a way to replace that real context name with us-ord-alpha in this case. Any hints how to do that?

fenio avatar Mar 06 '25 12:03 fenio

As a workaround I'm using context instead of cluster name in my prompt and the following snippet:

kubectl config rename-context $(kubectl config current-context) $(grep kubeswitch $KUBECONFIG | awk -F/ '{ print $1 }' | awk '{ print $2 }')

So I'm kinda all but leaving ticket open as exposing such info might be useful for other purposes.

fenio avatar Mar 06 '25 13:03 fenio