danielfoehrKn / kubeswitch

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

Bad index file - timing issue #101

Open MikaelElkiaer opened 11 months ago

MikaelElkiaer commented 11 months ago

Hi, love this tool and use it every day!

After adding a Vault KV2 store, I've started to sporadically seeing the following error:

$ switch
Error: could not unmarshal index file with path '/home/me/.kube/switch-state/switch.filesystem.default.index': yaml: line 5: could not find expected ':'
could not unmarshal index file with path '/home/me/.kube/switch-state/switch.filesystem.default.index': yaml: line 5: could not find expected ':'

It usually will occur after aborting a switch. Below is an example - the Error: abort is caused by a <C-c> or <esc> key press. After which I will just remove /home/me/.kube/switch-state/switch.filesystem.default.index and it will work again for some time.

$ cat ~/.kube/switch-state/switch.filesystem.default.index
kind: filesystem
contextToPathMapping:
  output/default: /home/me/Repositories/GitHub/org/helm-charts/charts/project/.debug/output/kubeconfig.yaml
$ switch
Error: abort
abort
$ switch
Error: could not unmarshal index file with path '/home/me/.kube/switch-state/switch.filesystem.default.index': yaml: line 5: could not find expected ':'
could not unmarshal index file with path '/home/me/.kube/switch-state/switch.filesystem.default.index': yaml: line 5: could not find expected ':'
$ cat ~/.kube/switch-state/switch.filesystem.default.index
kind: filesystem
contextToPathMapping:
  .kube/minikube: /home/me/.kube/config_minikube
rg/helm-charts/charts/project/.debug/output/kubeconfig.yaml
danielfoehrKn commented 11 months ago

Hi, thanks for reporting. I think that requires either some fallback logic to repair the index file or a signal handler for SIGTERM in the switcher binary that makes sure that the process only terminates after existing filesystem write operations are completed.

needleshaped commented 6 days ago

Workaround for me was rm -rf ~/.kube/switch-state/, s clean did not help.