Tramp's method "kubernetes" supports now optional namespace
* doc/misc/tramp.texi (Inline methods): Extend Kubernetes host name syntax by an optional namespace. (Kubernetes setup): Mention optional namespace part of the host name. * etc/NEWS: Tramp's method "kubernetes" supports now optional namespace. Fix typos. * lisp/net/tramp-container.el (tramp-kubernetes-namespace): Initialize with nil. Adapt docstring. (tramp-kubernetes--name-regexp): New defconst. (tramp-kubernetes--host-name-regexp): Change in order to cover also an optional namespace. (Bug#59797) (tramp-kubernetes--namespace): New defun. (tramp-kubernetes--context-namespace): Use it. (tramp-skeleton-kubernetes-vector): Add sanity check for superfluous user name or port number.
This commit is contained in:
parent
ba31c62f81
commit
d2cb9f2bf6
3 changed files with 78 additions and 41 deletions
|
@ -999,9 +999,11 @@ if desired.
|
|||
@cindex @option{kubernetes} method
|
||||
|
||||
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.
|
||||
@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. @samp{@var{pod}%@var{namespace}} as host name allows to use
|
||||
another namespace but the default one. This can also be combined with
|
||||
the @samp{@var{container}.} prefix.
|
||||
|
||||
This method does not support user names.
|
||||
|
||||
|
@ -3246,7 +3248,9 @@ by setting the pod annotation
|
|||
@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}.
|
||||
@code{tramp-kubernetes-context} or @code{tramp-kubernetes-namespace},
|
||||
respectively. An explicit @samp{%@var{namespace}} postfix in the host
|
||||
name takes precedence.
|
||||
|
||||
|
||||
@node Auto-save File Lock and Backup
|
||||
|
|
49
etc/NEWS
49
etc/NEWS
|
@ -24,11 +24,12 @@ applies, and please also update docstrings as needed.
|
|||
|
||||
* Installation Changes in Emacs 31.1
|
||||
|
||||
** When using GCC 4 or later to build Emacs on 32-bit x86 systems,
|
||||
'configure' now defaults to using the GCC options -mfpmath=sse (if the
|
||||
host system supports SSE2) or -fno-tree-sra (if not). These GCC options
|
||||
work around GCC bug 58416, which can cause Emacs to behave incorrectly
|
||||
in rare cases.
|
||||
** Changed GCC default options on 32-bit x86 systems.
|
||||
When using GCC 4 or later to build Emacs on 32-bit x86 systems,
|
||||
'configure' now defaults to using the GCC options '-mfpmath=sse' (if the
|
||||
host system supports SSE2) or '-fno-tree-sra' (if not). These GCC
|
||||
options work around GCC bug 58416, which can cause Emacs to behave
|
||||
incorrectly in rare cases.
|
||||
|
||||
|
||||
* Startup Changes in Emacs 31.1
|
||||
|
@ -37,7 +38,7 @@ in rare cases.
|
|||
* Changes in Emacs 31.1
|
||||
|
||||
---
|
||||
** "find-func.el" commands now have history enabled.
|
||||
** find-func.el commands now have history enabled.
|
||||
The 'find-function', 'find-library', 'find-face-definition', and
|
||||
'find-variable' commands now allow retrieving previous input using the
|
||||
usual minibuffer history commands. Each command has a separate history.
|
||||
|
@ -52,13 +53,13 @@ usual minibuffer history commands. Each command has a separate history.
|
|||
|
||||
---
|
||||
*** 'whitespace-cleanup' now adds missing newline at end of file.
|
||||
If 'whitespace-style' includes 'missing-newline-at-eof (which is the
|
||||
If 'whitespace-style' includes 'missing-newline-at-eof' (which is the
|
||||
default), the 'whitespace-cleanup' function will now add the newline.
|
||||
|
||||
** Eshell
|
||||
|
||||
---
|
||||
*** New option 'eshell-command-async-buffer'.
|
||||
*** New user option 'eshell-command-async-buffer'.
|
||||
This option lets you tell 'eshell-command' how to respond if its output
|
||||
buffer is already in use by another invocation of 'eshell-command', much
|
||||
like 'async-shell-command-buffer' does for 'shell-command'. By default,
|
||||
|
@ -68,7 +69,7 @@ necessary. To restore the previous behavior, set this option to
|
|||
|
||||
+++
|
||||
*** 'eshell-execute-file' is now an interactive command.
|
||||
Interactively, this now prompts for a script file to execute. With the
|
||||
Interactively, this now prompts for a script file to execute. With the
|
||||
prefix argument, it will also insert any output into the current buffer
|
||||
at point.
|
||||
|
||||
|
@ -79,8 +80,8 @@ where to send the standard error output. See the "(eshell) Entry
|
|||
Points" node in the Eshell manual for more details.
|
||||
|
||||
+++
|
||||
*** Eshell's built-in "wait" command now accepts a timeout.
|
||||
By passing "-t" or "--timeout", you can specify a maximum time to wait
|
||||
*** Eshell's built-in 'wait' command now accepts a timeout.
|
||||
By passing '-t' or '--timeout', you can specify a maximum time to wait
|
||||
for the processes to exit. Additionally, you can now wait for external
|
||||
processes by passing their PIDs.
|
||||
|
||||
|
@ -91,7 +92,7 @@ processes by passing their PIDs.
|
|||
Sliced images allow for more intuitive scrolling up/down by letting you
|
||||
scroll past each slice, instead of jumping past the entire image.
|
||||
Previously, SHR sliced images when zoomed to their original size, no
|
||||
matter how large or small that was). Now, SHR slices any images taller
|
||||
matter how large or small that was. Now, SHR slices any images taller
|
||||
than 'shr-sliced-image-height'. For more information, see the "(eww)
|
||||
Advanced" node in the EWW manual.
|
||||
|
||||
|
@ -111,13 +112,13 @@ point. If a region is active, it runs all the unit tests under the
|
|||
region. It is bound to 'C-c C-t t' in 'go-ts-mode'.
|
||||
|
||||
The 'go-ts-mode-test-this-file' command runs all unit tests in the current
|
||||
file. It is bound to 'C-c C-t f' in 'go-ts-mode'.
|
||||
file. It is bound to 'C-c C-t f' in 'go-ts-mode'.
|
||||
|
||||
The 'go-ts-mode-test-this-package' command runs all unit tests under the
|
||||
package of the current buffer. It is bound to 'C-c C-t p' in 'go-ts-mode'.
|
||||
|
||||
The 'go-ts-mode-build-tags' variable is available to set a list of build
|
||||
tags for the test commands.
|
||||
The 'go-ts-mode-build-tags' user option is available to set a list of
|
||||
build tags for the test commands.
|
||||
|
||||
** Emacs Lisp mode
|
||||
|
||||
|
@ -154,8 +155,18 @@ positives.
|
|||
---
|
||||
*** Dedicated buffer for plain text contents.
|
||||
When switching to the plain text contents with 'doc-view-open-text',
|
||||
DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you
|
||||
DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you
|
||||
back to real DocView buffer if it still exists.
|
||||
|
||||
** Tramp
|
||||
|
||||
+++
|
||||
*** Connection method "kubernetes" supports now optional namespace.
|
||||
The host name for Kubernetes connections can be of kind
|
||||
[CONTAINER.]POD[%NAMESPACE], in order to specify the namespace to be
|
||||
used. This overrides the setiing in 'tramp-kubernetes-namespace', if
|
||||
any.
|
||||
|
||||
|
||||
* New Modes and Packages in Emacs 31.1
|
||||
|
||||
|
@ -182,9 +193,9 @@ It has been obsolete since Emacs 26.1. Use the group 'text' instead.
|
|||
|
||||
---
|
||||
** Process execution has been optimized on Android.
|
||||
The run-time performance of subprocesses on recent Android releases
|
||||
where a userspace executable loader is required has been optimized on
|
||||
systems featuring Linux 3.5.0 and above.
|
||||
The run-time performance of subprocesses on recent Android releases,
|
||||
where a userspace executable loader is required, has been optimized on
|
||||
systems featuring GNU/Linux 3.5.0 and above.
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
|
|
@ -50,18 +50,14 @@
|
|||
;;
|
||||
;; Open file in a Kubernetes container:
|
||||
;;
|
||||
;; C-x C-f /kubernetes:[CONTAINER.]POD:/path/to/file
|
||||
;; C-x C-f /kubernetes:[CONTAINER.]POD[%NAMESPACE]:/path/to/file
|
||||
;;
|
||||
;; Where:
|
||||
;; POD is the pod to connect to.
|
||||
;; CONTAINER is the container to connect to (optional).
|
||||
;; By default, the first container in that pod will
|
||||
;; be used.
|
||||
;;
|
||||
;; Completion for POD and accessing it operate in the current
|
||||
;; namespace, use this command to change it:
|
||||
;;
|
||||
;; "kubectl config set-context --current --namespace=<name>"
|
||||
;; NAMESPACE is the namespace to be used (optional).
|
||||
;;
|
||||
;;
|
||||
;;
|
||||
|
@ -151,11 +147,14 @@ If it is nil, the default context will be used."
|
|||
:type '(choice (const :tag "Use default" nil)
|
||||
(string)))
|
||||
|
||||
(defcustom tramp-kubernetes-namespace "default"
|
||||
"Namespace of Kubernetes."
|
||||
(defcustom tramp-kubernetes-namespace nil
|
||||
"Namespace of Kubernetes.
|
||||
If it is nil, the current namespace will be used. An explicit NAMESPACE
|
||||
in the remote file name host part will override it."
|
||||
:group 'tramp
|
||||
:version "30.1"
|
||||
:type 'string)
|
||||
:version "31.1"
|
||||
:type '(choice (const :tag "Use default" nil)
|
||||
(string)))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defcustom tramp-toolbox-program "toolbox"
|
||||
|
@ -324,10 +323,18 @@ see its function help for a description of the format."
|
|||
(push (concat elt "." (car line)) names)))
|
||||
(mapcar (lambda (name) (list nil name)) (delq nil names))))))
|
||||
|
||||
;; <https://kubernetes.io/docs/concepts/overview/working-with-objects/names/>
|
||||
;; `lower' could also match non-ascii letters. But since this regexp
|
||||
;; is only used for strings matching `tramp-host-regexp', this doesn't
|
||||
;; hurt.
|
||||
(defconst tramp-kubernetes--name-regexp (rx (** 1 63 (any lower digit "-")))
|
||||
"Regexp matching kubernetes names.")
|
||||
|
||||
(defconst tramp-kubernetes--host-name-regexp
|
||||
(rx (? (group (regexp tramp-host-regexp)) ".")
|
||||
(group (regexp tramp-host-regexp)))
|
||||
"The CONTAINER.POD syntax of kubernetes host names in Tramp.")
|
||||
(rx bos (? (group (regexp tramp-kubernetes--name-regexp)) ".")
|
||||
(group (regexp tramp-kubernetes--name-regexp))
|
||||
(? "%" (group (regexp tramp-kubernetes--name-regexp))) eos)
|
||||
"The CONTAINER.POD%NAMESPACE syntax of kubernetes host names in Tramp.")
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-kubernetes--container (vec)
|
||||
|
@ -345,6 +352,16 @@ see its function help for a description of the format."
|
|||
(match-string 2 host)))
|
||||
""))
|
||||
|
||||
;;;###tramp-autoload
|
||||
(defun tramp-kubernetes--namespace (vec)
|
||||
"Extract the namespace from a kubernetes host name in VEC.
|
||||
Use `tramp-kubernetes-namespace' otherwise."
|
||||
(or (when-let ((_ vec)
|
||||
(host (tramp-file-name-host vec)))
|
||||
(and (string-match tramp-kubernetes--host-name-regexp host)
|
||||
(match-string 3 host)))
|
||||
tramp-kubernetes-namespace))
|
||||
|
||||
;; We must change `vec' and `default-directory' to the previous hop,
|
||||
;; in order to run `process-file' in a proper environment.
|
||||
(defmacro tramp-skeleton-kubernetes-vector (vec &rest body)
|
||||
|
@ -355,6 +372,11 @@ BODY is the backend specific code."
|
|||
(cond
|
||||
((null ,vec) tramp-null-hop)
|
||||
((equal (tramp-file-name-method ,vec) tramp-kubernetes-method)
|
||||
;; Sanity check. We don't support `user' or `port' in
|
||||
;; Kubernetes file names.
|
||||
(when (or (tramp-file-name-user-domain ,vec)
|
||||
(tramp-file-name-port ,vec))
|
||||
(tramp-user-error ,vec "Wrong kubernetes file name syntax"))
|
||||
(if (tramp-file-name-hop ,vec)
|
||||
(tramp-dissect-hop-name (tramp-file-name-hop ,vec))
|
||||
tramp-null-hop))
|
||||
|
@ -400,8 +422,8 @@ Obey `tramp-kubernetes-context'"
|
|||
#'identity
|
||||
`(,(when-let ((context (tramp-kubernetes--current-context vec)))
|
||||
(format "--context=%s" context))
|
||||
,(when tramp-kubernetes-namespace
|
||||
(format "--namespace=%s" tramp-kubernetes-namespace)))
|
||||
,(when-let ((namespace (tramp-kubernetes--namespace vec)))
|
||||
(format "--namespace=%s" namespace)))
|
||||
" "))
|
||||
|
||||
;;;###tramp-autoload
|
||||
|
@ -617,9 +639,9 @@ see its function help for a description of the format."
|
|||
;; This variable will be eval'ed in `tramp-expand-args'.
|
||||
(tramp-extra-expand-args
|
||||
. (?a (tramp-kubernetes--container (car tramp-current-connection))
|
||||
?h (tramp-kubernetes--pod (car tramp-current-connection))
|
||||
?x (tramp-kubernetes--context-namespace
|
||||
(car tramp-current-connection)))))
|
||||
?h (tramp-kubernetes--pod (car tramp-current-connection))
|
||||
?x (tramp-kubernetes--context-namespace
|
||||
(car tramp-current-connection)))))
|
||||
"Default connection-local variables for remote kubernetes connections.")
|
||||
|
||||
(connection-local-set-profile-variables
|
||||
|
|
Loading…
Add table
Reference in a new issue