Adapt Tramp's kubernetes integration

* doc/misc/tramp.texi (Inline methods): Shorten kubernetes entry.
(Kubernetes setup): New node.
(Top, Configuration): Add it to the menu.

* lisp/net/tramp-container.el (tramp-kubernetes--context-namespace):
Adapt dpcstring.
(tramp-kubernetes-connection-local-default-profile)
(tramp-kubernetes-connection-local-default-variables)
(tramp-flatpak-connection-local-default-profile)
(tramp-flatpak-connection-local-default-variables): Rename.

* lisp/net/tramp.el (tramp-expand-args): Use `tramp-compat-take'.

* test/lisp/net/tramp-tests.el (tramp-test34-connection-local-variables)
(tramp-test34-explicit-shell-file-name): Don't let-bind
`connection-local-profile-alist' and `connection-local-criteria-alist'.
This commit is contained in:
Michael Albinus 2023-06-28 16:53:01 +02:00
parent dcd9209095
commit c5d6102313
4 changed files with 42 additions and 24 deletions

View file

@ -142,6 +142,7 @@ on the remote host.
* Ssh setup:: Ssh setup hints.
* FUSE setup:: @acronym{FUSE} setup hints.
* Android shell setup:: Android shell setup hints.
* Kubernetes setup:: Kubernetes setup hints.
* Auto-save File Lock and Backup::
Auto-save, File Lock and Backup.
* Keeping files encrypted:: Protect remote files by encryption.
@ -700,6 +701,7 @@ on the remote host.
* Ssh setup:: Ssh setup hints.
* FUSE setup:: @acronym{FUSE} setup hints.
* Android shell setup:: Android shell setup hints.
* Kubernetes setup:: Kubernetes setup hints.
* Auto-save File Lock and Backup::
Auto-save, File Lock and Backup.
* Keeping files encrypted:: Protect remote files by encryption.
@ -921,16 +923,10 @@ if desired.
@cindex method @option{kubernetes}
@cindex @option{kubernetes} method
Integration for containers in Kubernetes pods. The host name is a pod
name returned by @samp{kubectl get pods}, or
@samp{@var{container}.@var{pod}} if an explicit container name shall
be used. Otherwise, the first container in a pod is used.
@vindex tramp-kubernetes-context
@vindex tramp-kubernetes-namespace
If another Kubernetes context or namespace shall be used, configure
the user options @code{tramp-kubernetes-context} and
@code{tramp-kubernetes-namespace}.
Integration for containers in Kubernetes pods. The host name is
@samp{@var{pod}}, or @samp{@var{container}.@var{pod}} if an
explicit container name shall be used. Otherwise, the first container
in a pod is used.
This method does not support user names.
@ -3122,6 +3118,29 @@ Open a remote connection with the more concise command @kbd{C-x C-f
@end itemize
@node Kubernetes setup
@section Kubernetes setup hints
With the @option{kubernetes} method, containers in Kubernetes pods can
be accessed. The host name is a pod name returned by @samp{kubectl
get pods}, or @samp{@var{container}.@var{pod}} if an explicit
container name shall be used. Otherwise, the first container in a pod
is used.
Sometimes, asynchronous processes for a host without a dedicated
container name show a warning like @samp{Defaulted container
"container1" out of: container1, container2}. This can be mitigated
by setting the pod annotation
@samp{kubectl.kubernetes.io/default-container} to a proper value
(@samp{container1} in this example).
@vindex tramp-kubernetes-context
@vindex tramp-kubernetes-namespace
@value{tramp} uses the default Kubernetes context and namespace. If
another context or namespace shall be used, configure the user options
@code{tramp-kubernetes-context} and @code{tramp-kubernetes-namespace}.
@node Auto-save File Lock and Backup
@section Auto-save, File Lock and Backup configuration
@cindex auto-save

View file

@ -256,7 +256,7 @@ Obey `tramp-kubernetes-context'"
;;;###tramp-autoload
(defun tramp-kubernetes--context-namespace (vec)
"The kubectl options for context and namespace."
"The kubectl options for context and namespace as string."
(mapconcat
#'identity
`(,(when-let ((context (tramp-kubernetes--current-context vec)))
@ -404,7 +404,7 @@ see its function help for a description of the format."
;; Default connection-local variables for Tramp.
(defconst tramp-container-connection-local-default-kubernetes-variables
(defconst tramp-kubernetes-connection-local-default-variables
'((tramp-config-check . tramp-kubernetes--current-context-data)
;; This variable will be eval'ed in `tramp-expand-args'.
(tramp-extra-expand-args
@ -414,24 +414,24 @@ see its function help for a description of the format."
"Default connection-local variables for remote kubernetes connections.")
(connection-local-set-profile-variables
'tramp-container-connection-local-default-kubernetes-profile
tramp-container-connection-local-default-kubernetes-variables)
'tramp-kubernetes-connection-local-default-profile
tramp-kubernetes-connection-local-default-variables)
(connection-local-set-profiles
`(:application tramp :protocol ,tramp-kubernetes-method)
'tramp-container-connection-local-default-kubernetes-profile)
'tramp-kubernetes-connection-local-default-profile)
(defconst tramp-container-connection-local-default-flatpak-variables
(defconst tramp-flatpak-connection-local-default-variables
`((tramp-remote-path . ,(cons "/app/bin" tramp-remote-path)))
"Default connection-local variables for remote flatpak connections.")
(connection-local-set-profile-variables
'tramp-container-connection-local-default-flatpak-profile
tramp-container-connection-local-default-flatpak-variables)
'tramp-flatpak-connection-local-default-profile
tramp-flatpak-connection-local-default-variables)
(connection-local-set-profiles
`(:application tramp :protocol ,tramp-flatpak-method)
'tramp-container-connection-local-default-flatpak-profile))
'tramp-flatpak-connection-local-default-profile))
(add-hook 'tramp-unload-hook
(lambda ()

View file

@ -4968,7 +4968,8 @@ a connection-local variable."
;; Merge both spec lists. Remove duplicate entries.
(while spec-list
(unless (member (car spec-list) extra-spec-list)
(setq extra-spec-list (append (take 2 spec-list) extra-spec-list)))
(setq extra-spec-list
(append (tramp-compat-take 2 spec-list) extra-spec-list)))
(setq spec-list (cddr spec-list)))
(setq spec (apply #'format-spec-make extra-spec-list))
;; Expand format spec.

View file

@ -6136,8 +6136,7 @@ INPUT, if non-nil, is a string sent to the process."
(inhibit-message t)
kill-buffer-query-functions
(clpa connection-local-profile-alist)
(clca connection-local-criteria-alist)
connection-local-profile-alist connection-local-criteria-alist)
(clca connection-local-criteria-alist))
(unwind-protect
(progn
(make-directory tmp-name1)
@ -6219,8 +6218,7 @@ INPUT, if non-nil, is a string sent to the process."
(let ((default-directory ert-remote-temporary-file-directory)
explicit-shell-file-name kill-buffer-query-functions
(clpa connection-local-profile-alist)
(clca connection-local-criteria-alist)
connection-local-profile-alist connection-local-criteria-alist)
(clca connection-local-criteria-alist))
(unwind-protect
(progn
(connection-local-set-profile-variables