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

Unable to fetch namespaces #107

Open
jeanfrancoisgratton opened this issue Jan 10, 2024 · 2 comments
Open

Unable to fetch namespaces #107

jeanfrancoisgratton opened this issue Jan 10, 2024 · 2 comments

Comments

@jeanfrancoisgratton
Copy link

jeanfrancoisgratton commented Jan 10, 2024

First off, I must be doing something wrong....

In my .zshrc, I export KUBECONFIG dynamically, this way:
export KUBECONFIG="$(printf '%s\n' ~/.kube/configs/*.k8sconfig 2>/dev/null | awk '{printf "%s:", $0}' | sed 's/:$//')" 2>/dev/null

This allows my variable to be up-to-date at each start of my shell, regardless of the contents in ~/.kube/configs/ . All of my kube config files have the .k8sconfig extension.

My switch-config.yaml file is this:
kind: SwitchConfig
version: v1alpha1
kubeconfigStores:

  • kind: filesystem
    showPrefix: false
    kubeconfigName: "*.k8sconfig"
    paths:
    • ~/.kube/configs

The problem I have right now is that I can select a context, but once done, if I come back with ks ns it breaks with the following error:
WARN[0000] failed to retrieve current namespaces: unable to create rest config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

Why is that, and how may I correct my setup ? Obviously I am missing something.

I currently have 2 config files in .kube/configs, but it will soon grow. I've tried exporting KUBECONFIG= one of those files. What happens then is that when I run switcher, it lists the contexts from KUBECONFIG, and then the contexts from the 2 files in .kube/configs/ .. This means one file is listed twice.

Moreover, regardless of which context I choose, when it exits and then I try switcher ns, regardless of which config file switch to, switcher ns will always lists the namespaces from the first selected file. As if my selection is disregarded past the first occurence.

@jeanfrancoisgratton
Copy link
Author

Trying to find some work-arounds, I've stumbled on this:

I have 2 config files: .kube/configs/cfg1.yaml, .kube/configs/cfg2.yaml.
I've then ran:

  • cd ~/.kube
  • kubectl config view --flatten > config
  • rm -rf configs switch-state .switch* <-- wiping out everything kubeswitcher-related, to start from scratch
    New switch-config.yaml:

kind: SwitchConfig
version: v1alpha1
kubeconfigStores:

  • kind: filesystem
    showPrefix: true
    paths:
    • ~/.kube/config

Ok 2 things:

  • My 2 cfg files are duplicated (so 4 files show, 2 with the .kube/ prefix, 2 without.
  • regardless if I take .kube/cfg1.yaml or cfg1.yaml, fetch the namespaces thereafter (switcher ns), once I exit and choose the 2nd configuration, as mentioned way above, a further switcher ns command will still fetch cfg1's namespaces

@danielfoehrKn
Copy link
Owner

danielfoehrKn commented Apr 17, 2024

Do you use the switcher binary only - or also the switch script - which is required to set the KUBECONFIG environment variable? To verify, check that after running switch, that the environment variable is set like so:

KUBECONFIG=/Users/<my_user>/.kube/.switch_tmp/config.3093589165.tmp

a further switcher ns command will still fetch cfg1's namespaces

Another clue that the new KUBECONFIG env variable is not set, as the namespace command simply reads the currently set KUBECONFIG env variable to determine the kubeconfig to use.

My 2 cfg files are duplicated (so 4 files show, 2 with the .kube/ prefix, 2 without.

Probably the contexts without the switch prefix are the contexts taken from your current Kubeconfig file set via the KUBECONFIG environment variable (it also checks this file to be compatible with kubectx, but ignores it when it is a kubeswitch-created temporary kubeconfig to not show duplicate entries)

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