summaryrefslogtreecommitdiff
path: root/lisp/net/tramp-container.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2022-10-25 16:34:42 +0200
committerMichael Albinus <michael.albinus@gmx.de>2022-10-25 16:34:42 +0200
commitfe816fc679ead2100cddb4e51bc81c329bcb4265 (patch)
tree5a8b9214e16e0ee5f05344bed773ff02546521ea /lisp/net/tramp-container.el
parent8c3b8c36677eedfc3839488e3cef9f6a5937baa3 (diff)
downloademacs-fe816fc679ead2100cddb4e51bc81c329bcb4265.tar.gz
emacs-fe816fc679ead2100cddb4e51bc81c329bcb4265.tar.bz2
emacs-fe816fc679ead2100cddb4e51bc81c329bcb4265.zip
Handle context changes in Tramp kubernetes method
* doc/misc/tramp.texi (Inline methods): Remove note about cache reset. (File name completion): Add tramp-completion-use-cache. * etc/NEWS: Add 'tramp-completion-use-cache'. * lisp/net/tramp-cache.el (tramp-completion-use-cache): New defcustom. (tramp-parse-connection-properties): Use it. * lisp/net/tramp-container.el (tramp-docker--completion-function) (tramp-kubernetes--completion-function): Ensure the processes run locally. (tramp-kubernetes--current-context-data): New defun. (tramp-methods) <kubernetes>: Add `tramp-config-check'. * lisp/net/tramp-sh.el (tramp-open-connection-setup-interactive-shell): Handle `tramp-login-args'. * lisp/net/tramp.el (tramp-methods): Adapt docstring.
Diffstat (limited to 'lisp/net/tramp-container.el')
-rw-r--r--lisp/net/tramp-container.el25
1 files changed, 23 insertions, 2 deletions
diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el
index e104babed27..0879d6f1856 100644
--- a/lisp/net/tramp-container.el
+++ b/lisp/net/tramp-container.el
@@ -101,7 +101,8 @@
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
+ (when-let ((default-directory tramp-compat-temporary-file-directory)
+ (raw-list (shell-command-to-string
(concat tramp-docker-program
" ps --format '{{.ID}}\t{{.Names}}'")))
(lines (split-string raw-list "\n" 'omit))
@@ -121,7 +122,8 @@ see its function help for a description of the format."
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
+ (when-let ((default-directory tramp-compat-temporary-file-directory)
+ (raw-list (shell-command-to-string
(concat tramp-kubernetes-program
" get pods --no-headers "
"-o custom-columns=NAME:.metadata.name")))
@@ -130,6 +132,24 @@ see its function help for a description of the format."
(list nil name))
names)))
+(defun tramp-kubernetes--current-context-data (vec)
+ "Return Kubernetes current context data as JSONPATH string."
+ (with-temp-buffer
+ (when (zerop
+ (tramp-call-process
+ vec tramp-kubernetes-program nil t nil
+ "config" "current-context"))
+ (goto-char (point-min))
+ (let ((current-context (buffer-substring (point) (line-end-position))))
+ (erase-buffer)
+ (when (zerop
+ (tramp-call-process
+ vec tramp-kubernetes-program nil t nil
+ "config" "view" "-o"
+ (format
+ "jsonpath='{.contexts[?(@.name == \"%s\")]}'" current-context)))
+ (buffer-string))))))
+
;;;###tramp-autoload
(defvar tramp-default-remote-shell) ;; Silence byte compiler.
@@ -165,6 +185,7 @@ see its function help for a description of the format."
("-it")
("--")
("%l")))
+ (tramp-config-check tramp-kubernetes--current-context-data)
(tramp-remote-shell ,tramp-default-remote-shell)
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-i" "-c"))))