Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context switch is not working - possible clash with same context name value #137

Open
vinibali opened this issue Aug 29, 2024 · 4 comments

Comments

@vinibali
Copy link

Hi!
I have some kubeconfigs which has the same context name inside. Even kubectl is not able identify both if these are listed in the KUBECONFIG env variable, like

KUBECONFIG=/home/user/.kube/cluster1.conf:/home/user/.kube/cluster2.conf

Is there some other way to identify the kubeconfigs with the context-cluster key?
Unfortunately I couldn't rename the context, because that breaks the functionality of the config.
I experience pretty much the same with kubectx:
ahmetb/kubectx#428

@danielfoehrKn
Copy link
Owner

Try to put the kubeconfigs under different parent filesystem paths (directory).

KUBECONFIG=/home/user/.kube/parent1/cluster1.conf:/home/user/.kube/parent2/cluster2.conf

@vinibali
Copy link
Author

vinibali commented Sep 2, 2024

that's not working unfortunately, kubectl shows only one context, while switcher lists two, but it's doesn't matter where I'm navigating with the cursor it shows the same kubeconfig on the right.

@danielfoehrKn
Copy link
Owner

Do you have https://github.com/danielfoehrKn/kubeswitch/blob/master/types/config.go#L116 set to true? Then for both kubeconfigs, it should show the distinct parent directory followed by the same context name.

@vinibali
Copy link
Author

Yes, that's true by default. As it turned out this is not working, I even tried to set the default setting here:

$ cat switch-config.yaml
kind: SwitchConfig
version: v1alpha1
showPrefix: true
$ echo $KUBECONFIG
KUBECONFIG=/home/user/.kube/cluster1.conf:/home/user/.kube/cluster2.conf

The only way, where the different config directories was shown, when I utilized the filesystem kind:

$ cat switch-config.yaml
kind: SwitchConfig
version: v1alpha1
kubeconfigStores:
- kind: filesystem
  kubeconfigName: "cluster*.conf"
  showPrefix: true
  showPreview: false
  paths:
    - ~/.kube/parent1
    - ~/.kube/parent2

In this case I could see 4 contexts, but 3 had the same preview and 1 was the different one. What I can see now it's not working if you are using the KUBECONFIG with the slimmed down switch-config.
The preview supposed to work if the KUBECONFIG environment variable is unset and the filesystem kind identifies the configs in their own directory. Unfortunately in this case I don't know how how to target configs/contexts as kubectl is looking for the K8s cluster on the local machine.

Sorry for the late reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants