abrochard / kubel

Emacs extension for controlling Kubernetes with limited permissions
GNU General Public License v3.0
267 stars 44 forks source link

Presets for kubeconfig files #119

Open pashazz opened 11 months ago

pashazz commented 11 months ago

So I have different clusters and different KUBECONFIG files for each cluster: my work clusters, production, and home kind clusters they all have different kubeconfigs.

I wonder if I'd be able to maybe provide a list of kubeconfig files and then hit some button and circle through them?

Now I feel I only can hit K and choose KUBECONFIG file from my directory structure each time I launch Emacs

abrochard commented 10 months ago

Hi @pashazz , I gave this some thought and I think the simplest at this point is for you to customize the kubel-set-kubectl-config-file function with an advice. I did some local testing and I think something like

(defconst my-kubeconfig-files '("LIST" "OF" "FILEPATHS"))

(defun set-my-kubeconfig-files (set-config-file)
    (funcall set-config-file (completing-read "Select kubeconfig file: " my-kubeconfig-files)))

(advice-add 'kubel-set-kubectl-config-file :around #'set-my-kubeconfig-files)

I used the official doc as a guide https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html but in short my understanding is that you override the kubel-set-kubectl-config-file with the custom function set-my-kubeconfig-files, which has the presets of your kubeconfig files, lets you select one, and then passes it to the old kubel-set-kubectl-config-file