danielfoehrKn / kubeswitch

The kubectx for operators.
https://danielfoehrkn.medium.com/the-case-of-kubeswitch-aff4b6a04ae7
Apache License 2.0
832 stars 80 forks source link

Error saving history when switching context #29

Closed rvillane closed 2 years ago

rvillane commented 2 years ago

Hello, I'm testing the latest kubeswitch on my Mac

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

when I try to run the interactive interface to select the context to switch to, I've got the following error:

$ switcher --debug
DEBU[0000] Using kubeconfig path from flag /Users/myuser/.kube/config 
DEBU[0000] Added store with kind filesystem and ID filesystem.env-and-flag 
WARN[0006] failed to append context to history file: cannot open file: open /Users/myuser/.kube/.switch_history: no such file or directory 
/Users/myuser/.kube/.switch_tmp/config.122399507.tmp

the interactive screen works fine, I see the list of contexts just fine and I can select the new context just fine, but when I hit enter the set the context, the error above shows up.

If I create an empty /Users/myuser/.kube/.switch_history file, then I get a different error message:

$ touch /Users/myuser/.kube/.switch_history
crmar@crmac10-lp Documents $ switcher --debug
DEBU[0000] Using kubeconfig path from flag /Users/myuser/.kube/config 
DEBU[0000] Added store with kind filesystem and ID filesystem.env-and-flag 
WARN[0003] failed to append context to history file: seek /Users/myuser/.kube/.switch_history: invalid argument 
/Users/myuser/.kube/.switch_tmp/config.1892608840.tmp

This is the very first time I run kubeswitch, then I guess not having the .switch_history file is expected in that case.

any ideas ?

danielfoehrKn commented 2 years ago

Thanks for reporting!

I could reproduce the error and published release 0.6.1 that includes a fix. Please let me know if that works for you.

In addition, I see that you use the switcher binary directly. Please do not do this - rather use the switch command by sourcing the switch.sh script. This is done automatically when installing with brew.

rvillane commented 2 years ago

ok, I have upgraded to release 0.6.1 and also sourced switch.sh script and now I can change context just fine, the only minor detail I noticed is that if I run the version command, it keeps showing 0.6.0:

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

thanks for the quick fix

danielfoehrKn commented 2 years ago

Ah shoot, I forgot to increase the version for the patch release in the source code (not automated yet). Thanks for reporting. Open an issue any time if you find further issues.