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

Error: failed to get namespace of current context: context with name "/Users/userid/.kube/config" not found #32

Closed
rubber-ant opened this issue Feb 21, 2022 · 9 comments

Comments

@rubber-ant
Copy link

rubber-ant commented Feb 21, 2022

echo $SHELL
/bin/zsh

switcher version
Switch:
		version     : v0.6.0
		build date  : 2021-12-15
		go version  : go1.17.4
		go compiler : gc
		platform    : darwin/amd6

switch gke_foo-europe-west1
Error: failed to get namespace of current context: context with name "/Users/userid/.kube/config" not found
grep context -A1 /Users/userid/.kube/config
contexts:
- context:
    cluster: gke_foo-europe-west1
--

when I run only switch, the context is listed without issue.

What I'm doing wrong ?

@danielfoehrKn
Copy link
Owner

What I'm doing wrong ?

Probably nothing as this is possibly a bug. It seems to be related to the recently introduced namespace switching functionality.
I will get back to it when finding some time (hopefully next week).
Thanks for reporting already.

Does switch and then checking out the context via the fuzzy search work for you?

@danielfoehrKn
Copy link
Owner

Also you could post a sanitized version of this kubeconfig + your switch-config.yaml

@rubber-ant
Copy link
Author

rubber-ant commented Feb 21, 2022

after the run switch the fuzzy search works and I can select the context without issue.

Not working: `switch -d , the context doesn't get deleted.

switch -d context1
deleted context context1  from /Users/userid/.kube/.switch_tmp/config.4004739986.tmp

Works only if I run switch -d and then I select the context from fuzzy search

Not working `switch .`
> switch
switched to context "context1".
>k get namespace
NAME              STATUS   AGE
default           Active   760d
> switch
switched to context "context2".
>k get namespace
NAME              STATUS   AGE
default           Active   601d
> switch .
Error: failed to set namespace "default": failed to set namespace "default": context with name "/Users/userid/.kube/config" not found

the kubeconfig is quite a default configuration without any directories and for some reason switch-config.yaml is not even present in the ~/.kube/

 ls -al ~/.kube/
total 56
drwxr-xr-x    7 userid  staff    224 21 Feb 14:56 .
drwxr-xr-x+ 100 userid  staff   3200 21 Feb 15:50 ..
-rw-r--r--    1 userid  staff    666 21 Feb 16:06 .switch_history
drwx------   16 userid  staff    512 21 Feb 16:07 .switch_tmp
drwxr-x---    4 userid  staff    128 20 Feb 14:45 cache
-rw-------@   1 userid  staff  24166 21 Feb 14:48 config
drwxr-xr-x    6 userid  staff    192 21 Feb 11:46 switch-state
ls -al ~/.kube/switch-state/namespace
total 8
drwxr-xr-x  3 userid  staff   96 21 Feb 09:35 .
drwxr-xr-x  6 userid  staff  192 21 Feb 11:46 ..
-rw-r--r--  1 userid  staff   69 21 Feb 09:35 context1

grep switch ~/.zshrc
source /usr/local/bin/switch.sh
sw_vers
ProductName:	macOS
ProductVersion:	11.6
BuildVersion:	20G165

@danielfoehrKn
Copy link
Owner

danielfoehrKn commented Feb 21, 2022

the kubeconfig is quite a default configuration without any directories and for some reason switch-config.yaml is not even present in the ~/.kube/

ok thanks, just wanted to check if there is any custom config present.

Works only if I run switch -d and then I select the context from fuzzy search

That is expected as switch -d only works on the local copy of the kubeconfig file. So in your case , the context is only deleted from the temporary file, not the original kubeconfig.

I ll have a look at that namespace issue, sorry for the inconvenience.

@danielfoehrKn
Copy link
Owner

Sorry for the delay. I think I have found the problem, but it would be nice if you could test it on your system.

This is the commit.
You can use the from source installation method described here.
Thanks a lot!

@ipclaudio
Copy link

Hi @danielfoehrKn

thanks for the fix

$ switch -v
Switch:
		version     : v0.6.1
		build date  : 2022-03-31
		go version  : go1.17.6
		go compiler : gc
		platform    : darwin/amd64

both of these 2 commands are working now!

$ switch gke_foo-europe-west1
switched to context "gke_foo-europe-west1".

$ switch -

are you going to look into this?

$ switch -d context1
deleted context context1  from /Users/userid/.kube/.switch_tmp/config.4004739986.tmp

@danielfoehrKn
Copy link
Owner

are you going to look into this?

What is the problem here? For the output I can see that the context was removed - mind you, removed from the temporary kubeconfig file. It will not be removed from the original kubeconfig file.
To remove the context from the original kubeconfig file, you need to do export KUBECONFIG=./my-original and then run switch -d context1

@rubber-ant
Copy link
Author

@danielfoehrKn thanks!

@danielfoehrKn
Copy link
Owner

Just released version 0.6.2 which includes the fix - thanks again for reporting. Feel free to open again if you come across the issue again.

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

3 participants