aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Gunbin2022-10-04 20:35:01 +0300
committerFilipp Gunbin2022-10-04 20:35:01 +0300
commitec9f89784528b34b0ce03934b22498fae3eaf999 (patch)
tree0aee241e916f1da02a2ea57e558324a321df8505
parentda02b9edadbc809b25ac83eccf64089f1cf3b160 (diff)
downloademacs-scratch/tramp-kubernetes.tar.gz
emacs-scratch/tramp-kubernetes.zip
Add lisp/net/tramp-kubernetes.elscratch/tramp-kubernetes
* lisp/net/tramp-kubernetes.el: New file. * doc/misc/tramp.texi (Inline methods): Add kubernetes. (Customizing Methods): Remove kubernetes-tramp. * etc/NEWS: Mention new Tramp method "kubernetes". * lisp/net/tramp-compat.el (kubernetes-tramp): Warn if that package is used.
-rw-r--r--doc/misc/tramp.texi17
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/net/tramp-compat.el3
-rw-r--r--lisp/net/tramp-kubernetes.el102
4 files changed, 115 insertions, 11 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index a182c0510d7..9e6de15f1f4 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -912,6 +912,14 @@ Integration for Docker containers. A container is accessed via
912@samp{user} is the (optional) user that you want to use, and 912@samp{user} is the (optional) user that you want to use, and
913@samp{container} is the id or name of the container. 913@samp{container} is the id or name of the container.
914 914
915@item @option{kubernetes}
916@cindex method @option{kubernetes}
917@cindex @option{kubernetes} method
918
919Integration for Kubernetes pod containers. A container is accessed
920via @file{@trampfn{kubernetes,pod,/path/to/file}}, where @samp{pod} is
921the name of the pod. Currently, the first container in a pod is used.
922
915@end table 923@end table
916 924
917 925
@@ -1772,15 +1780,6 @@ They can be installed with Emacs's Package Manager. This includes
1772@c @item ibuffer-tramp.el 1780@c @item ibuffer-tramp.el
1773@c Contact Svend Sorensen <svend@@ciffer.net> 1781@c Contact Svend Sorensen <svend@@ciffer.net>
1774 1782
1775@item kubernetes-tramp
1776@cindex method @option{kubectl}
1777@cindex @option{kubectl} method
1778Integration for Docker containers deployed in a Kubernetes cluster. A
1779container is accessed via
1780@file{@trampfn{kubectl,user@@container,/path/to/file}}, @samp{user}
1781and @samp{container} have the same meaning as with the @option{docker}
1782method.
1783
1784@item lxc-tramp 1783@item lxc-tramp
1785@cindex method @option{lxc} 1784@cindex method @option{lxc}
1786@cindex @option{lxc} method 1785@cindex @option{lxc} method
diff --git a/etc/NEWS b/etc/NEWS
index d7bc4b0e0c2..6104e71ed44 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2409,8 +2409,8 @@ and friends.
2409** Tramp 2409** Tramp
2410 2410
2411+++ 2411+++
2412*** New connection method "docker". 2412*** New connection methods "docker" and "kubernetes".
2413It allows accessing environments provided by Docker. 2413They allows accessing environments provided by Docker / Kubernetes.
2414 2414
2415--- 2415---
2416*** Tramp supports abbreviating remote home directories now. 2416*** Tramp supports abbreviating remote home directories now.
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index f6cc1034ca5..c510626ecad 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -53,6 +53,9 @@
53(with-eval-after-load 'docker-tramp 53(with-eval-after-load 'docker-tramp
54 (warn (concat "Package `docker-tramp' has been obsoleted, " 54 (warn (concat "Package `docker-tramp' has been obsoleted, "
55 "please use integrated package `tramp-docker'"))) 55 "please use integrated package `tramp-docker'")))
56(with-eval-after-load 'kubernetes-tramp
57 (warn (concat "Package `kubernetes-tramp' has been obsoleted, "
58 "please use integrated package `tramp-kubernetes'")))
56 59
57;; For not existing functions, obsolete functions, or functions with a 60;; For not existing functions, obsolete functions, or functions with a
58;; changed argument list, there are compiler warnings. We want to 61;; changed argument list, there are compiler warnings. We want to
diff --git a/lisp/net/tramp-kubernetes.el b/lisp/net/tramp-kubernetes.el
new file mode 100644
index 00000000000..0ad333f8187
--- /dev/null
+++ b/lisp/net/tramp-kubernetes.el
@@ -0,0 +1,102 @@
1;;; tramp-kubernetes.el --- Tramp integration for Kubernetes containers -*- lexical-binding: t; -*-
2
3;; Copyright © 2022 Free Software Foundation, Inc.
4
5;; Keywords: comm, processes, kubernetes
6;; Package: tramp
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;; `tramp-kubernetes' allows Tramp access to environments provided by
26;; Kubernetes.
27;;
28;; The kubectl program should be configured correctly. You may also
29;; want to set the namespace to use:
30;;
31;; kubectl config set-context --current --namespace=<my-namespace>
32;;
33;; ## Usage
34;;
35;; Open a file in container:
36;;
37;; C-x C-f /kubernetes:POD:/path/to/file
38;;
39;; Where:
40;; POD is the pod to connect to.
41;; By default, the first container in that pod will be
42;; connected to.
43
44;;; Code:
45
46(require 'tramp)
47
48;;;###tramp-autoload
49(defcustom tramp-kubernetes-program "kubectl"
50 "Name of the Kubernetes client program."
51 :group 'tramp
52 :version "29.1"
53 :type '(choice (const "kubectl")
54 (string)))
55
56;;;###tramp-autoload
57(defconst tramp-kubernetes-method "kubernetes"
58 "Tramp method name to use to connect to Kubernetes containers.")
59
60;;;###tramp-autoload
61(defun tramp-kubernetes--completion-function (&rest _args)
62 "List Kubernetes pods available for connection.
63
64This function is used by `tramp-set-completion-function', please
65see its function help for a description of the format."
66 (when-let ((raw-list (shell-command-to-string
67 (concat tramp-kubernetes-program
68 " get pods --no-headers "
69 "-o custom-columns=NAME:.metadata.name")))
70 (names (split-string raw-list "\n" 'omit)))
71 (mapcar (lambda (name)
72 (list nil name))
73 names)))
74
75;;;###tramp-autoload
76(defvar tramp-default-remote-shell) ;; Silence byte compiler.
77
78;;;###tramp-autoload
79(tramp--with-startup
80 (push `(,tramp-kubernetes-method
81 (tramp-login-program ,tramp-kubernetes-program)
82 (tramp-login-args (("exec")
83 ("%h")
84 ("-it")
85 ("--")
86 ("%l")))
87 (tramp-remote-shell ,tramp-default-remote-shell)
88 (tramp-remote-shell-login ("-l"))
89 (tramp-remote-shell-args ("-i" "-c")))
90 tramp-methods)
91
92 (tramp-set-completion-function
93 tramp-kubernetes-method
94 '((tramp-kubernetes--completion-function ""))))
95
96(add-hook 'tramp-unload-hook
97 (lambda ()
98 (unload-feature 'tramp-kubernetes 'force)))
99
100(provide 'tramp-kubernetes)
101
102;;; tramp-kubernetes.el ends here