abrochard / kubel

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

TRAMP + Emacs 30 #109

Open johnhamelink opened 1 year ago

johnhamelink commented 1 year ago

Hi there,

I'm running Emacs from master branch. Emacs 29 comes with support for Kubernetes, Podman and Docker as TRAMP "inline methods" (see here).

abrochard commented 1 year ago

Hi @johnhamelink , Thank you for sharing this! I was not aware of these changes at all. This is actually a trickier change than first anticipated because we also have to keep things working for people running versions anterior to 29:

I'm also still on 28 and not sure when I will upgrade/find time to work on this.

johnhamelink commented 1 year ago

We can probably do some smart logic and try to default/fallback to tramp-kubernetes-program if defined similarly we should keep the old TRAMP method if tramp-kubernetes-method isn't defined

Sounds good!

I think that config use/set-context is global?

That's right. I wonder if instead we could supply environment variables to the underlying kubectl process?

Another issue is that according to the docs, "The first container in a pod is used", which is rather limiting for Kubel's use-case. Similar tools like k9s allow you to select the pod - often the first pod is actually istio-proxy or a similar "sidecar" pod which is less interesting.

linktohack commented 1 year ago

This works for me

  (with-eval-after-load 'tramp
    (require 'tramp-container)
    (when-let* ((method (thread-last tramp-methods
                     (seq-find #'(lambda (it) (pcase it (`("kubernetes" . ,_) t))))))
        (updated (pcase method (`(,_ . ,rest) `("kubectl" . ,rest)))))
      (add-to-list 'tramp-methods updated)))

It inserts kubectl method with the same config of kubernetes method defined in tramp-container

Hope it helps.

johnhamelink commented 1 year ago

FYI it's now possible to define a container ID along with a pod in Emacs master: https://github.com/emacs-mirror/emacs/blob/master/lisp/net/tramp-container.el#L47

It seems that the namespace and context can be defined now too: https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS#L439