rottencandy / vimkubectl

Manage Kubernetes resources from Vim
https://www.vim.org/scripts/script.php?script_id=5862
MIT License
76 stars 5 forks source link

Commands fail when cluster does not have a service account named "default" #12

Closed joeblubaugh closed 4 months ago

joeblubaugh commented 4 months ago

Thanks for the plugin! It's really convenient to have this instead of running :terminal to work with k8s in vim.

I work with a number of clusters that do not have a default serviceaccount. However, to fetch the active namespace for all kubectl commands, the plugin uses the command:

" Get currently active namespace
fun! vimkubectl#kube#fetchActiveNamespace() abort
  return system(
        \ s:craftCmd('get sa default -o ''jsonpath={.metadata.namespace}''')
        \ )
endfun

I also can't find a way to explicitly set the namespace when running a given command, so I don't think there's a workaround to this problem.

However, it's also possible to use this command to get the current namespace from local kube context:

kubectl config view --minify -o jsonpath='{..namespace}'

I'm suggesting replacing the current fetchActiveNamespace implementation with this config view command because it doesn't rely on certain service accounts existing.

rottencandy commented 4 months ago

Thx for the suggestion! Fixed in https://github.com/rottencandy/vimkubectl/commit/acf03ab0a5b83275951b19653b6980b1b85a165e