From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59797: 30.0.50; [wishlist] Using namespaces in Tramp's kubernetes integration Date: Thu, 25 Jul 2024 10:20:40 +0200 Message-ID: <87ed7hkhlz.fsf@gmx.de> References: <87wn78lu7n.fsf@gmx.de> <874ju96e2g.fsf@gmx.de> <87bkogr2e5.fsf@gmx.de> <87y1kaq7ty.fsf@gmx.de> <87ttggnvf5.fsf@gmx.de> <87plr4nqmh.fsf@gmx.de> <87plr2ka7v.fsf@gmx.de> Reply-To: Michael Albinus Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37580"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Aaron Gonzales , 59797@debbugs.gnu.org, Filipp Gunbin , Warren Lynn To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 25 10:22:14 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sWtjp-0009aF-PQ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 Jul 2024 10:22:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWtja-0007Sj-Bh; Thu, 25 Jul 2024 04:21:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWtjX-0007SV-Qs for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 04:21:55 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWtjX-0005ol-Dx for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 04:21:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sWtjd-00013L-Vl for bug-gnu-emacs@gnu.org; Thu, 25 Jul 2024 04:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Jul 2024 08:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59797 X-GNU-PR-Package: emacs Original-Received: via spool by 59797-submit@debbugs.gnu.org id=B59797.17218956663969 (code B ref 59797); Thu, 25 Jul 2024 08:22:01 +0000 Original-Received: (at 59797) by debbugs.gnu.org; 25 Jul 2024 08:21:06 +0000 Original-Received: from localhost ([127.0.0.1]:35497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sWtik-00011x-8D for submit@debbugs.gnu.org; Thu, 25 Jul 2024 04:21:06 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:53583) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sWtih-00011L-JT for 59797@debbugs.gnu.org; Thu, 25 Jul 2024 04:21:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1721895643; x=1722500443; i=michael.albinus@gmx.de; bh=yM4VbIWCPLXgMNhZW3BQOPwyDtw5Oalh7BD0I4G0PEs=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=NpIXV3R/gkMfKh71l76YsBeF43iQGX+V8vAH4nHuPREbh+rnM2TquJX1UHVPgiZN o5Sav0vqrax6JWXEyaWKaRqLMzFchQcWjwN83DawtXteG6uEBn+QLmplrAJdABF5H EvbX5qeCKjIOcv1QId8eKBHfNxVskZs0NOT0ph2TffSIYb/Z7Patq3MTODZ+mrB9d xoxXD0gfGr811TL2s4SzHF7MvqoEClwkF6BmAxj/yhbsRoI2PmfdNdZQUZE5g3db/ k2irDe1bUnZ4aFW/iR2Qzb6N5fi+GLPI6ZCZxP0GoboZWmCsv2r/rBPnpbjgGPu6s nZWP+2UOeW6uINp45A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.38.155]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MWRRZ-1sm8FV43VD-00RY4q; Thu, 25 Jul 2024 10:20:43 +0200 In-Reply-To: (Eshel Yaron's message of "Wed, 24 Jul 2024 19:30:29 +0200") X-Provags-ID: V03:K1:yBHYkBPLcYx9Z0ptHmy68MEECQ8Ll5cFtBTD8SVWKtosiHAlGHF cJG6OFn/xKPqztxOTPW+9l2P3Ix9P77w+QQFa8QNXyMAWb3S+VVLACCwfcu05LXWLThWRr7 HPD1IDrlXsYBhaNBiQNc6+ZBTyOBE7+H6ubaVArX+XSfcj+zEyxVt4KiVkqEVn95NSdLLzY jLjVZxJdvIFz+7roQr5iw== UI-OutboundReport: notjunk:1;M01:P0:uNebUgQl6bo=;IqPpxSVdO0Prf8WKq9iqpQ3vYiF /iZRkCGnd/zy8F6dSIQfjHga/hLPacL2KqzmR7oTFeX1D4MPHLLj2fpNtMi+zRESm684a2niQ /OodHVlqGYKpPh0CO+vwMmVYw03DUtNQw+eQDuNWOJY3n5TUgwUsl+PwZy3moxjHChFbtjmS6 QcXqX7tZz56gQn2EMQQtKBQjivAxQzAqjoJtBunqbYEI6bSCRIblQKE+b/YSF87ptZoyAikQ1 i4qhD3PBD73BXKTVYXpwet5BuswcxeFUA2fmB27hXiEPBPgTJYNrIBFiLnlQU2ewiAO7gjWPv 6+7RMALMF4OjoF3Ko9JfgYKySE5z1R24eF4qJmSElZ+hZpCGH3admvY+7Aav4KYvA9IpUJFBd 7B4C8sYloGhseuOLnYdQ02qRfHvjGtQVZx6e3GTTr4yRe6XMmBzMyIr/PUfG16l5WsCVGaxER nRVr43Q+VeU3hU4r/shBsdE8qCO9Sv8S1xNoUkcmszDP2i4AdWnuapJMZjNPdSeBXOJ32mnBz lYZW7EklaW4CLnkEsNf0vo3RN7y0KOGdfj/lfrxmj0bd13ptIUx+894TZdjyHdN70uMH79RTL Hq4acAKP4EWaJWjP6RRKJhT/g/IY2gLxShRrwgIn6Vvib+swSMod5HT08oGKuO9O5Vd+DBZht TCmlZk68D0kU0+XLF69jlhRVhs16tdJHsQi9X/vz5TGtjd8e4Nbb43bqeSSxTUemA641MXzQl U8J57l0Ie3GeHS78e3GElmUzZAYbUtu7I3A3qMRAyQR0MN3OIzs9OawxHVjnzZ3dUxX+pVqN X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289290 Archived-At: --=-=-= Content-Type: text/plain Eshel Yaron writes: > Hi Michael, Hi Eshel, > From a quick test, this mostly works fine. There's one issue (typo?) in > tramp-kubernetes--namespace that causes a regression when there's no > explicit namespace and tramp-kubernetes-namespace is nil, it returns an > empty string instead of nil. I'fixed this, see appended revised patch. I've changed also the default value of tramp-kubernetes-namespace to nil; we shouldn't assume that everybody wants "default" as default. Could you give it a short test, please? > Cheers, > > Eshel Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/tramp-container.el b/lisp/tramp-container.el index 02512e64..bd5736e6 100644 =2D-- a/lisp/tramp-container.el +++ b/lisp/tramp-container.el @@ -50,18 +50,14 @@ ;; ;; Open file in a Kubernetes container: ;; -;; C-x C-f /kubernetes:[CONTAINER.]POD:/path/to/file +;; C-x C-f /kubernetes:[CONTAINER.]POD[%NAMESPACE]:/path/to/file ;; ;; Where: ;; POD is the pod to connect to. ;; CONTAINER is the container to connect to (optional). ;; By default, the first container in that pod will ;; be used. -;; -;; Completion for POD and accessing it operate in the current -;; namespace, use this command to change it: -;; -;; "kubectl config set-context --current --namespace=3D" +;; NAMESPACE is the namespace to be used (optional). ;; ;; ;; @@ -151,10 +147,12 @@ If it is nil, the default context will be used." :type '(choice (const :tag "Use default" nil) (string))) -(defcustom tramp-kubernetes-namespace "default" - "Namespace of Kubernetes." +(defcustom tramp-kubernetes-namespace nil + "Namespace of Kubernetes. +If it is nil, the current namespace will be used. An explicit NAMESPACE +in the remote file name host part will override it." :group 'tramp - :version "30.1" + :version "31.1" :type 'string) ;;;###tramp-autoload @@ -324,10 +322,18 @@ see its function help for a description of the forma= t." (push (concat elt "." (car line)) names))) (mapcar (lambda (name) (list nil name)) (delq nil names)))))) +;; +;; `lower' could also match non-ascii letters. But since this regexp +;; is only used for strings matching `tramp-host-regexp', this doesn't +;; hurt. +(defconst tramp-kubernetes--name-regexp (rx (** 1 63 (any lower digit "-"= ))) + "Regexp matching kubernetes names.") + (defconst tramp-kubernetes--host-name-regexp - (rx (? (group (regexp tramp-host-regexp)) ".") - (group (regexp tramp-host-regexp))) - "The CONTAINER.POD syntax of kubernetes host names in Tramp.") + (rx bos (? (group (regexp tramp-kubernetes--name-regexp)) ".") + (group (regexp tramp-kubernetes--name-regexp)) + (? "%" (group (regexp tramp-kubernetes--name-regexp))) eos) + "The CONTAINER.POD%NAMESPACE syntax of kubernetes host names in Tramp."= ) ;;;###tramp-autoload (defun tramp-kubernetes--container (vec) @@ -345,6 +351,16 @@ see its function help for a description of the format= ." (match-string 2 host))) "")) +;;;###tramp-autoload +(defun tramp-kubernetes--namespace (vec) + "Extract the namespace from a kubernetes host name in VEC. +Use `tramp-kubernetes-namespace' otherwise." + (or (when-let ((_ vec) + (host (tramp-file-name-host vec))) + (and (string-match tramp-kubernetes--host-name-regexp host) + (match-string 3 host))) + tramp-kubernetes-namespace)) + ;; We must change `vec' and `default-directory' to the previous hop, ;; in order to run `process-file' in a proper environment. (defmacro tramp-skeleton-kubernetes-vector (vec &rest body) @@ -355,6 +371,11 @@ BODY is the backend specific code." (cond ((null ,vec) tramp-null-hop) ((equal (tramp-file-name-method ,vec) tramp-kubernetes-method) + ;; Sanity check. We don't support `user' or `port' in + ;; kubernetes file names. + (when (or (tramp-file-name-user-domain ,vec) + (tramp-file-name-port ,vec)) + (tramp-user-error ,vec "Wrong kubernetes file name syntax")) (if (tramp-file-name-hop ,vec) (tramp-dissect-hop-name (tramp-file-name-hop ,vec)) tramp-null-hop)) @@ -400,8 +421,8 @@ Obey `tramp-kubernetes-context'" #'identity `(,(when-let ((context (tramp-kubernetes--current-context vec))) (format "--context=3D%s" context)) - ,(when tramp-kubernetes-namespace - (format "--namespace=3D%s" tramp-kubernetes-namespace))) + ,(when-let ((namespace (tramp-kubernetes--namespace vec))) + (format "--namespace=3D%s" namespace))) " ")) ;;;###tramp-autoload @@ -617,9 +638,9 @@ see its function help for a description of the format.= " ;; This variable will be eval'ed in `tramp-expand-args'. (tramp-extra-expand-args . (?a (tramp-kubernetes--container (car tramp-current-connection)) - ?h (tramp-kubernetes--pod (car tramp-current-connection)) - ?x (tramp-kubernetes--context-namespace - (car tramp-current-connection))))) + ?h (tramp-kubernetes--pod (car tramp-current-connection)) + ?x (tramp-kubernetes--context-namespace + (car tramp-current-connection))))) "Default connection-local variables for remote kubernetes connections.= ") (connection-local-set-profile-variables --=-=-=--