--- /dev/null
+;;; kubed-common.el --- Common definitons for Kubed -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Free Software Foundation, Inc.
+
+;; Author: Eshel Yaron <me@eshelyaron.com>
+;; Keywords: tools
+
+;;; Commentary:
+
+;; This library provides definitions that both `kubed' and `kubed-tramp'
+;; require.
+
+;;; Code:
+
+(defvar kubed-tramp-method "kubedv1" ;Versioned, for compatibility.
+ ;; (find-file "/kubedv1:CONTEXT%NAMESPACE%POD%CONTAINER:/some/file")
+ "Name of the Kubed Tramp method.")
+
+(defcustom kubed-kubectl-program "kubectl"
+ "Name of `kubectl' executable to use for interacting with Kubernetes."
+ :type 'string
+ :group 'kubed)
+
+(provide 'kubed-common)
+;;; kubed-tramp.el ends here
;;; Code:
-(require 'kubed)
+(require 'kubed-common)
(require 'tramp)
(defun kubed-tramp--context (vec)
(nth 3 (split-string host "%")))
""))
-(defvar kubed-tramp-method "kubedv1" ;Versioned, for compatibility.
- ;; (find-file "/kubedv1:CONTEXT%NAMESPACE%POD%CONTAINER:/some/file")
- "Name of the Kubed Tramp method.")
-
-(defun kubed-tramp-remote-file-name (context namespace pod &optional file-name)
- "Return Tramp remote FILE-NAME for POD in NAMESPACE and CONTEXT."
- (concat "/" kubed-tramp-method ":"
- context "%" namespace "%" pod
- "%" (kubed-read-container pod "Container" t context namespace)
- ":" file-name))
-
;;;###autoload
(defun kubed-tramp-context (file-name)
"Extract `kubectl' context from Kubed Tramp remote file name FILE-NAME."
(unless (assoc kubed-tramp-method tramp-methods)
(user-error "Kubed Tramp support requires Tramp version 2.7 or later")))
-(when (boundp 'tramp-extra-expand-args) ; Tramp 2.7+
- (setf (alist-get kubed-tramp-method tramp-methods nil nil #'string=)
- `((tramp-login-program ,kubed-kubectl-program)
- (tramp-login-args (("exec")
- ("--context" "%x")
- ("--namespace" "%y")
- ("-c" "%a")
- ("%h")
- ("-it")
- ("--")
- ("%l")))
- (tramp-direct-async (,tramp-default-remote-shell "-c"))
- (tramp-remote-shell ,tramp-default-remote-shell)
- (tramp-remote-shell-login ("-l"))
- (tramp-remote-shell-args ("-i" "-c"))))
-
- (connection-local-set-profile-variables
- 'kubed-tramp-connection-local-default-profile
- '((tramp-extra-expand-args
- ?a (kubed-tramp--container (car tramp-current-connection))
- ?h (kubed-tramp--pod (car tramp-current-connection))
- ?x (kubed-tramp--context (car tramp-current-connection))
- ?y (kubed-tramp--namespace (car tramp-current-connection)))))
-
- (connection-local-set-profiles
- `(:application tramp :protocol ,kubed-tramp-method)
- 'kubed-tramp-connection-local-default-profile))
+;;;###autoload
+(defun kubed-tramp-enable ()
+ "Enable Kubed integration with Tramp."
+ (when (boundp 'tramp-extra-expand-args) ; Tramp 2.7+
+
+ (setf (alist-get kubed-tramp-method tramp-methods nil nil #'string=)
+ `((tramp-login-program ,kubed-kubectl-program)
+ (tramp-login-args (("exec")
+ ("--context" "%x")
+ ("--namespace" "%y")
+ ("-c" "%a")
+ ("%h")
+ ("-it")
+ ("--")
+ ("%l")))
+ (tramp-direct-async (,tramp-default-remote-shell "-c"))
+ (tramp-remote-shell ,tramp-default-remote-shell)
+ (tramp-remote-shell-login ("-l"))
+ (tramp-remote-shell-args ("-i" "-c"))))
+
+ (connection-local-set-profile-variables
+ 'kubed-tramp-connection-local-default-profile
+ '((tramp-extra-expand-args
+ ?a (kubed-tramp--container (car tramp-current-connection))
+ ?h (kubed-tramp--pod (car tramp-current-connection))
+ ?x (kubed-tramp--context (car tramp-current-connection))
+ ?y (kubed-tramp--namespace (car tramp-current-connection)))))
+
+ (connection-local-set-profiles
+ `(:application tramp :protocol ,kubed-tramp-method)
+ 'kubed-tramp-connection-local-default-profile)))
+
+;;;###autoload (with-eval-after-load 'tramp (kubed-tramp-enable))
(provide 'kubed-tramp)
;;; kubed-tramp.el ends here
;;; Code:
+(require 'kubed-common)
+
(defgroup kubed nil
"Kubernetes interface."
:group 'tools)
-(defcustom kubed-kubectl-program "kubectl"
- "Name of `kubectl' executable to use for interacting with Kubernetes."
- :type 'string)
-
(defcustom kubed-default-context-and-namespace nil
"Default `kubectl' context and Kubernetes namespace.
"\\)")
1))
+(defun kubed-remote-file-name (context namespace pod &optional file-name)
+ "Return remote FILE-NAME for POD in NAMESPACE and CONTEXT."
+ (concat "/" kubed-tramp-method ":"
+ context "%" namespace "%" pod
+ "%" (kubed-read-container pod "Container" t context namespace)
+ ":" file-name))
+
(declare-function kubed-tramp-context "kubed-tramp" (file-name))
(declare-function kubed-tramp-namespace "kubed-tramp" (file-name))
(declare-function kubed-tramp-assert-support "kubed-tramp" ())
-(declare-function kubed-tramp-remote-file-name "kubed-tramp"
- (context namespace pod &optional file-name))
;;;###autoload (autoload 'kubed-display-pod "kubed" nil t)
;;;###autoload (autoload 'kubed-edit-pod "kubed" nil t)
("F" "Forward port" kubed-pods-forward-port)])
(dired "C-d" "Start Dired in"
(kubed-tramp-assert-support)
- (dired (kubed-tramp-remote-file-name
+ (dired (kubed-remote-file-name
kubed-list-context kubed-list-namespace pod)))
(shell "s" "Start shell in"
(kubed-tramp-assert-support)
- (let* ((default-directory (kubed-tramp-remote-file-name
+ (let* ((default-directory (kubed-remote-file-name
kubed-list-context kubed-list-namespace pod)))
(shell
(concat "*Kubed Shell "