emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/tramp-kubernetes 73e1122e4c: Add lisp/net/tramp-kubernetes.el


From: Filipp Gunbin
Subject: scratch/tramp-kubernetes 73e1122e4c: Add lisp/net/tramp-kubernetes.el
Date: Mon, 3 Oct 2022 16:42:48 -0400 (EDT)

branch: scratch/tramp-kubernetes
commit 73e1122e4c0254e494bf0a5347d7186c3f2b4c7a
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>

    Add lisp/net/tramp-kubernetes.el
---
 lisp/net/tramp-kubernetes.el | 103 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/lisp/net/tramp-kubernetes.el b/lisp/net/tramp-kubernetes.el
new file mode 100644
index 0000000000..ae52a8c596
--- /dev/null
+++ b/lisp/net/tramp-kubernetes.el
@@ -0,0 +1,103 @@
+;;; tramp-kubernetes.el --- Tramp integration for Kubernetes containers  -*- 
lexical-binding: t; -*-
+
+;; Copyright © 2022 Free Software Foundation, Inc.
+
+;; Keywords: comm, processes, kubernetes
+;; Package: tramp
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; `tramp-kubernetes' allows Tramp access to environments provided by
+;; Kubernetes.
+;;
+;; The kubectl program should be configured correctly.  You may also
+;; want to set the namespace to use (otherwise you'll be getting the
+;; possibly long list equivalent to what "get -A" returns):
+;;
+;; kubectl config set-context --current --namespace=<my-namespace>
+;;
+;; ## Usage
+;;
+;; Open a file in container:
+;;
+;;     C-x C-f /kubernetes:POD:/path/to/file
+;;
+;; Where:
+;;     POD     is the pod to connect to.
+;;             By default, the first container in that pod will be
+;;             connected to.
+
+;;; Code:
+
+(require 'tramp)
+
+;;;###tramp-autoload
+(defcustom tramp-kubernetes-program "kubectl"
+  "Name of the Kubernetes client program."
+  :group 'tramp
+  :version "29.1"
+  :type '(choice (const "kubectl")
+                 (string)))
+
+;;;###tramp-autoload
+(defconst tramp-kubernetes-method "kubernetes"
+  "Tramp method name to use to connect to Kubernetes containers.")
+
+;;;###tramp-autoload
+(defun tramp-kubernetes--completion-function (&rest _args)
+  "List Kubernetes pods available for connection.
+
+This function is used by `tramp-set-completion-function', please
+see its function help for a description of the format."
+  (when-let ((raw-list (shell-command-to-string
+                       (concat tramp-kubernetes-program
+                                " get pods --no-headers "
+                                "-o custom-columns=NAME:.metadata.name")))
+             (names (split-string raw-list "\n" 'omit)))
+    (mapcar (lambda (name)
+              (list nil name))
+            names)))
+
+;;;###tramp-autoload
+(defvar tramp-default-remote-shell) ;; Silence byte compiler.
+
+;;;###tramp-autoload
+(tramp--with-startup
+ (push `(,tramp-kubernetes-method
+         (tramp-login-program ,tramp-kubernetes-program)
+         (tramp-login-args (("exec")
+                            ("%h")
+                            ("-it")
+                            ("--")
+                           ("%l")))
+         (tramp-remote-shell ,tramp-default-remote-shell)
+         (tramp-remote-shell-login ("-l"))
+         (tramp-remote-shell-args ("-i" "-c")))
+       tramp-methods)
+
+ (tramp-set-completion-function
+  tramp-kubernetes-method
+  '((tramp-kubernetes--completion-function ""))))
+
+(add-hook 'tramp-unload-hook
+         (lambda ()
+           (unload-feature 'tramp-kubernetes 'force)))
+
+(provide 'tramp-kubernetes)
+
+;;; tramp-kubernetes.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]