diff options
| author | Michael Albinus | 2024-07-25 13:38:27 +0200 |
|---|---|---|
| committer | Michael Albinus | 2024-07-25 13:38:27 +0200 |
| commit | d2cb9f2bf6ef9f3fcd8c21455ca1f1e624e61bf4 (patch) | |
| tree | bedfa9e6605e1cb123dfd90e4fd8ebb24f34fd04 | |
| parent | ba31c62f815537c0412eb84e8188cc5c3c4948b1 (diff) | |
| download | emacs-d2cb9f2bf6ef9f3fcd8c21455ca1f1e624e61bf4.tar.gz emacs-d2cb9f2bf6ef9f3fcd8c21455ca1f1e624e61bf4.zip | |
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.
| -rw-r--r-- | doc/misc/tramp.texi | 12 | ||||
| -rw-r--r-- | etc/NEWS | 49 | ||||
| -rw-r--r-- | lisp/net/tramp-container.el | 58 |
3 files changed, 78 insertions, 41 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index eddf0272641..e548432700f 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -999,9 +999,11 @@ if desired. | |||
| 999 | @cindex @option{kubernetes} method | 999 | @cindex @option{kubernetes} method |
| 1000 | 1000 | ||
| 1001 | Integration for containers in Kubernetes pods. The host name is | 1001 | Integration for containers in Kubernetes pods. The host name is |
| 1002 | @samp{@var{pod}}, or @samp{@var{container}.@var{pod}} if an | 1002 | @samp{@var{pod}}, or @samp{@var{container}.@var{pod}} if an explicit |
| 1003 | explicit container name shall be used. Otherwise, the first container | 1003 | container name shall be used. Otherwise, the first container in a pod |
| 1004 | in a pod is used. | 1004 | is used. @samp{@var{pod}%@var{namespace}} as host name allows to use |
| 1005 | another namespace but the default one. This can also be combined with | ||
| 1006 | the @samp{@var{container}.} prefix. | ||
| 1005 | 1007 | ||
| 1006 | This method does not support user names. | 1008 | This method does not support user names. |
| 1007 | 1009 | ||
| @@ -3246,7 +3248,9 @@ by setting the pod annotation | |||
| 3246 | @vindex tramp-kubernetes-namespace | 3248 | @vindex tramp-kubernetes-namespace |
| 3247 | @value{tramp} uses the default Kubernetes context and namespace. If | 3249 | @value{tramp} uses the default Kubernetes context and namespace. If |
| 3248 | another context or namespace shall be used, configure the user options | 3250 | another context or namespace shall be used, configure the user options |
| 3249 | @code{tramp-kubernetes-context} and @code{tramp-kubernetes-namespace}. | 3251 | @code{tramp-kubernetes-context} or @code{tramp-kubernetes-namespace}, |
| 3252 | respectively. An explicit @samp{%@var{namespace}} postfix in the host | ||
| 3253 | name takes precedence. | ||
| 3250 | 3254 | ||
| 3251 | 3255 | ||
| 3252 | @node Auto-save File Lock and Backup | 3256 | @node Auto-save File Lock and Backup |
| @@ -24,11 +24,12 @@ applies, and please also update docstrings as needed. | |||
| 24 | 24 | ||
| 25 | * Installation Changes in Emacs 31.1 | 25 | * Installation Changes in Emacs 31.1 |
| 26 | 26 | ||
| 27 | ** When using GCC 4 or later to build Emacs on 32-bit x86 systems, | 27 | ** Changed GCC default options on 32-bit x86 systems. |
| 28 | 'configure' now defaults to using the GCC options -mfpmath=sse (if the | 28 | When using GCC 4 or later to build Emacs on 32-bit x86 systems, |
| 29 | host system supports SSE2) or -fno-tree-sra (if not). These GCC options | 29 | 'configure' now defaults to using the GCC options '-mfpmath=sse' (if the |
| 30 | work around GCC bug 58416, which can cause Emacs to behave incorrectly | 30 | host system supports SSE2) or '-fno-tree-sra' (if not). These GCC |
| 31 | in rare cases. | 31 | options work around GCC bug 58416, which can cause Emacs to behave |
| 32 | incorrectly in rare cases. | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | * Startup Changes in Emacs 31.1 | 35 | * Startup Changes in Emacs 31.1 |
| @@ -37,7 +38,7 @@ in rare cases. | |||
| 37 | * Changes in Emacs 31.1 | 38 | * Changes in Emacs 31.1 |
| 38 | 39 | ||
| 39 | --- | 40 | --- |
| 40 | ** "find-func.el" commands now have history enabled. | 41 | ** find-func.el commands now have history enabled. |
| 41 | The 'find-function', 'find-library', 'find-face-definition', and | 42 | The 'find-function', 'find-library', 'find-face-definition', and |
| 42 | 'find-variable' commands now allow retrieving previous input using the | 43 | 'find-variable' commands now allow retrieving previous input using the |
| 43 | usual minibuffer history commands. Each command has a separate history. | 44 | usual minibuffer history commands. Each command has a separate history. |
| @@ -52,13 +53,13 @@ usual minibuffer history commands. Each command has a separate history. | |||
| 52 | 53 | ||
| 53 | --- | 54 | --- |
| 54 | *** 'whitespace-cleanup' now adds missing newline at end of file. | 55 | *** 'whitespace-cleanup' now adds missing newline at end of file. |
| 55 | If 'whitespace-style' includes 'missing-newline-at-eof (which is the | 56 | If 'whitespace-style' includes 'missing-newline-at-eof' (which is the |
| 56 | default), the 'whitespace-cleanup' function will now add the newline. | 57 | default), the 'whitespace-cleanup' function will now add the newline. |
| 57 | 58 | ||
| 58 | ** Eshell | 59 | ** Eshell |
| 59 | 60 | ||
| 60 | --- | 61 | --- |
| 61 | *** New option 'eshell-command-async-buffer'. | 62 | *** New user option 'eshell-command-async-buffer'. |
| 62 | This option lets you tell 'eshell-command' how to respond if its output | 63 | This option lets you tell 'eshell-command' how to respond if its output |
| 63 | buffer is already in use by another invocation of 'eshell-command', much | 64 | buffer is already in use by another invocation of 'eshell-command', much |
| 64 | like 'async-shell-command-buffer' does for 'shell-command'. By default, | 65 | 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 | |||
| 68 | 69 | ||
| 69 | +++ | 70 | +++ |
| 70 | *** 'eshell-execute-file' is now an interactive command. | 71 | *** 'eshell-execute-file' is now an interactive command. |
| 71 | Interactively, this now prompts for a script file to execute. With the | 72 | Interactively, this now prompts for a script file to execute. With the |
| 72 | prefix argument, it will also insert any output into the current buffer | 73 | prefix argument, it will also insert any output into the current buffer |
| 73 | at point. | 74 | at point. |
| 74 | 75 | ||
| @@ -79,8 +80,8 @@ where to send the standard error output. See the "(eshell) Entry | |||
| 79 | Points" node in the Eshell manual for more details. | 80 | Points" node in the Eshell manual for more details. |
| 80 | 81 | ||
| 81 | +++ | 82 | +++ |
| 82 | *** Eshell's built-in "wait" command now accepts a timeout. | 83 | *** Eshell's built-in 'wait' command now accepts a timeout. |
| 83 | By passing "-t" or "--timeout", you can specify a maximum time to wait | 84 | By passing '-t' or '--timeout', you can specify a maximum time to wait |
| 84 | for the processes to exit. Additionally, you can now wait for external | 85 | for the processes to exit. Additionally, you can now wait for external |
| 85 | processes by passing their PIDs. | 86 | processes by passing their PIDs. |
| 86 | 87 | ||
| @@ -91,7 +92,7 @@ processes by passing their PIDs. | |||
| 91 | Sliced images allow for more intuitive scrolling up/down by letting you | 92 | Sliced images allow for more intuitive scrolling up/down by letting you |
| 92 | scroll past each slice, instead of jumping past the entire image. | 93 | scroll past each slice, instead of jumping past the entire image. |
| 93 | Previously, SHR sliced images when zoomed to their original size, no | 94 | Previously, SHR sliced images when zoomed to their original size, no |
| 94 | matter how large or small that was). Now, SHR slices any images taller | 95 | matter how large or small that was. Now, SHR slices any images taller |
| 95 | than 'shr-sliced-image-height'. For more information, see the "(eww) | 96 | than 'shr-sliced-image-height'. For more information, see the "(eww) |
| 96 | Advanced" node in the EWW manual. | 97 | Advanced" node in the EWW manual. |
| 97 | 98 | ||
| @@ -111,13 +112,13 @@ point. If a region is active, it runs all the unit tests under the | |||
| 111 | region. It is bound to 'C-c C-t t' in 'go-ts-mode'. | 112 | region. It is bound to 'C-c C-t t' in 'go-ts-mode'. |
| 112 | 113 | ||
| 113 | The 'go-ts-mode-test-this-file' command runs all unit tests in the current | 114 | The 'go-ts-mode-test-this-file' command runs all unit tests in the current |
| 114 | file. It is bound to 'C-c C-t f' in 'go-ts-mode'. | 115 | file. It is bound to 'C-c C-t f' in 'go-ts-mode'. |
| 115 | 116 | ||
| 116 | The 'go-ts-mode-test-this-package' command runs all unit tests under the | 117 | The 'go-ts-mode-test-this-package' command runs all unit tests under the |
| 117 | package of the current buffer. It is bound to 'C-c C-t p' in 'go-ts-mode'. | 118 | package of the current buffer. It is bound to 'C-c C-t p' in 'go-ts-mode'. |
| 118 | 119 | ||
| 119 | The 'go-ts-mode-build-tags' variable is available to set a list of build | 120 | The 'go-ts-mode-build-tags' user option is available to set a list of |
| 120 | tags for the test commands. | 121 | build tags for the test commands. |
| 121 | 122 | ||
| 122 | ** Emacs Lisp mode | 123 | ** Emacs Lisp mode |
| 123 | 124 | ||
| @@ -154,8 +155,18 @@ positives. | |||
| 154 | --- | 155 | --- |
| 155 | *** Dedicated buffer for plain text contents. | 156 | *** Dedicated buffer for plain text contents. |
| 156 | When switching to the plain text contents with 'doc-view-open-text', | 157 | When switching to the plain text contents with 'doc-view-open-text', |
| 157 | DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you | 158 | DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you |
| 158 | back to real DocView buffer if it still exists. | 159 | back to real DocView buffer if it still exists. |
| 160 | |||
| 161 | ** Tramp | ||
| 162 | |||
| 163 | +++ | ||
| 164 | *** Connection method "kubernetes" supports now optional namespace. | ||
| 165 | The host name for Kubernetes connections can be of kind | ||
| 166 | [CONTAINER.]POD[%NAMESPACE], in order to specify the namespace to be | ||
| 167 | used. This overrides the setiing in 'tramp-kubernetes-namespace', if | ||
| 168 | any. | ||
| 169 | |||
| 159 | 170 | ||
| 160 | * New Modes and Packages in Emacs 31.1 | 171 | * New Modes and Packages in Emacs 31.1 |
| 161 | 172 | ||
| @@ -182,9 +193,9 @@ It has been obsolete since Emacs 26.1. Use the group 'text' instead. | |||
| 182 | 193 | ||
| 183 | --- | 194 | --- |
| 184 | ** Process execution has been optimized on Android. | 195 | ** Process execution has been optimized on Android. |
| 185 | The run-time performance of subprocesses on recent Android releases | 196 | The run-time performance of subprocesses on recent Android releases, |
| 186 | where a userspace executable loader is required has been optimized on | 197 | where a userspace executable loader is required, has been optimized on |
| 187 | systems featuring Linux 3.5.0 and above. | 198 | systems featuring GNU/Linux 3.5.0 and above. |
| 188 | 199 | ||
| 189 | 200 | ||
| 190 | ---------------------------------------------------------------------- | 201 | ---------------------------------------------------------------------- |
diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 02512e64ef6..27bad70753c 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el | |||
| @@ -50,18 +50,14 @@ | |||
| 50 | ;; | 50 | ;; |
| 51 | ;; Open file in a Kubernetes container: | 51 | ;; Open file in a Kubernetes container: |
| 52 | ;; | 52 | ;; |
| 53 | ;; C-x C-f /kubernetes:[CONTAINER.]POD:/path/to/file | 53 | ;; C-x C-f /kubernetes:[CONTAINER.]POD[%NAMESPACE]:/path/to/file |
| 54 | ;; | 54 | ;; |
| 55 | ;; Where: | 55 | ;; Where: |
| 56 | ;; POD is the pod to connect to. | 56 | ;; POD is the pod to connect to. |
| 57 | ;; CONTAINER is the container to connect to (optional). | 57 | ;; CONTAINER is the container to connect to (optional). |
| 58 | ;; By default, the first container in that pod will | 58 | ;; By default, the first container in that pod will |
| 59 | ;; be used. | 59 | ;; be used. |
| 60 | ;; | 60 | ;; NAMESPACE is the namespace to be used (optional). |
| 61 | ;; Completion for POD and accessing it operate in the current | ||
| 62 | ;; namespace, use this command to change it: | ||
| 63 | ;; | ||
| 64 | ;; "kubectl config set-context --current --namespace=<name>" | ||
| 65 | ;; | 61 | ;; |
| 66 | ;; | 62 | ;; |
| 67 | ;; | 63 | ;; |
| @@ -151,11 +147,14 @@ If it is nil, the default context will be used." | |||
| 151 | :type '(choice (const :tag "Use default" nil) | 147 | :type '(choice (const :tag "Use default" nil) |
| 152 | (string))) | 148 | (string))) |
| 153 | 149 | ||
| 154 | (defcustom tramp-kubernetes-namespace "default" | 150 | (defcustom tramp-kubernetes-namespace nil |
| 155 | "Namespace of Kubernetes." | 151 | "Namespace of Kubernetes. |
| 152 | If it is nil, the current namespace will be used. An explicit NAMESPACE | ||
| 153 | in the remote file name host part will override it." | ||
| 156 | :group 'tramp | 154 | :group 'tramp |
| 157 | :version "30.1" | 155 | :version "31.1" |
| 158 | :type 'string) | 156 | :type '(choice (const :tag "Use default" nil) |
| 157 | (string))) | ||
| 159 | 158 | ||
| 160 | ;;;###tramp-autoload | 159 | ;;;###tramp-autoload |
| 161 | (defcustom tramp-toolbox-program "toolbox" | 160 | (defcustom tramp-toolbox-program "toolbox" |
| @@ -324,10 +323,18 @@ see its function help for a description of the format." | |||
| 324 | (push (concat elt "." (car line)) names))) | 323 | (push (concat elt "." (car line)) names))) |
| 325 | (mapcar (lambda (name) (list nil name)) (delq nil names)))))) | 324 | (mapcar (lambda (name) (list nil name)) (delq nil names)))))) |
| 326 | 325 | ||
| 326 | ;; <https://kubernetes.io/docs/concepts/overview/working-with-objects/names/> | ||
| 327 | ;; `lower' could also match non-ascii letters. But since this regexp | ||
| 328 | ;; is only used for strings matching `tramp-host-regexp', this doesn't | ||
| 329 | ;; hurt. | ||
| 330 | (defconst tramp-kubernetes--name-regexp (rx (** 1 63 (any lower digit "-"))) | ||
| 331 | "Regexp matching kubernetes names.") | ||
| 332 | |||
| 327 | (defconst tramp-kubernetes--host-name-regexp | 333 | (defconst tramp-kubernetes--host-name-regexp |
| 328 | (rx (? (group (regexp tramp-host-regexp)) ".") | 334 | (rx bos (? (group (regexp tramp-kubernetes--name-regexp)) ".") |
| 329 | (group (regexp tramp-host-regexp))) | 335 | (group (regexp tramp-kubernetes--name-regexp)) |
| 330 | "The CONTAINER.POD syntax of kubernetes host names in Tramp.") | 336 | (? "%" (group (regexp tramp-kubernetes--name-regexp))) eos) |
| 337 | "The CONTAINER.POD%NAMESPACE syntax of kubernetes host names in Tramp.") | ||
| 331 | 338 | ||
| 332 | ;;;###tramp-autoload | 339 | ;;;###tramp-autoload |
| 333 | (defun tramp-kubernetes--container (vec) | 340 | (defun tramp-kubernetes--container (vec) |
| @@ -345,6 +352,16 @@ see its function help for a description of the format." | |||
| 345 | (match-string 2 host))) | 352 | (match-string 2 host))) |
| 346 | "")) | 353 | "")) |
| 347 | 354 | ||
| 355 | ;;;###tramp-autoload | ||
| 356 | (defun tramp-kubernetes--namespace (vec) | ||
| 357 | "Extract the namespace from a kubernetes host name in VEC. | ||
| 358 | Use `tramp-kubernetes-namespace' otherwise." | ||
| 359 | (or (when-let ((_ vec) | ||
| 360 | (host (tramp-file-name-host vec))) | ||
| 361 | (and (string-match tramp-kubernetes--host-name-regexp host) | ||
| 362 | (match-string 3 host))) | ||
| 363 | tramp-kubernetes-namespace)) | ||
| 364 | |||
| 348 | ;; We must change `vec' and `default-directory' to the previous hop, | 365 | ;; We must change `vec' and `default-directory' to the previous hop, |
| 349 | ;; in order to run `process-file' in a proper environment. | 366 | ;; in order to run `process-file' in a proper environment. |
| 350 | (defmacro tramp-skeleton-kubernetes-vector (vec &rest body) | 367 | (defmacro tramp-skeleton-kubernetes-vector (vec &rest body) |
| @@ -355,6 +372,11 @@ BODY is the backend specific code." | |||
| 355 | (cond | 372 | (cond |
| 356 | ((null ,vec) tramp-null-hop) | 373 | ((null ,vec) tramp-null-hop) |
| 357 | ((equal (tramp-file-name-method ,vec) tramp-kubernetes-method) | 374 | ((equal (tramp-file-name-method ,vec) tramp-kubernetes-method) |
| 375 | ;; Sanity check. We don't support `user' or `port' in | ||
| 376 | ;; Kubernetes file names. | ||
| 377 | (when (or (tramp-file-name-user-domain ,vec) | ||
| 378 | (tramp-file-name-port ,vec)) | ||
| 379 | (tramp-user-error ,vec "Wrong kubernetes file name syntax")) | ||
| 358 | (if (tramp-file-name-hop ,vec) | 380 | (if (tramp-file-name-hop ,vec) |
| 359 | (tramp-dissect-hop-name (tramp-file-name-hop ,vec)) | 381 | (tramp-dissect-hop-name (tramp-file-name-hop ,vec)) |
| 360 | tramp-null-hop)) | 382 | tramp-null-hop)) |
| @@ -400,8 +422,8 @@ Obey `tramp-kubernetes-context'" | |||
| 400 | #'identity | 422 | #'identity |
| 401 | `(,(when-let ((context (tramp-kubernetes--current-context vec))) | 423 | `(,(when-let ((context (tramp-kubernetes--current-context vec))) |
| 402 | (format "--context=%s" context)) | 424 | (format "--context=%s" context)) |
| 403 | ,(when tramp-kubernetes-namespace | 425 | ,(when-let ((namespace (tramp-kubernetes--namespace vec))) |
| 404 | (format "--namespace=%s" tramp-kubernetes-namespace))) | 426 | (format "--namespace=%s" namespace))) |
| 405 | " ")) | 427 | " ")) |
| 406 | 428 | ||
| 407 | ;;;###tramp-autoload | 429 | ;;;###tramp-autoload |
| @@ -617,9 +639,9 @@ see its function help for a description of the format." | |||
| 617 | ;; This variable will be eval'ed in `tramp-expand-args'. | 639 | ;; This variable will be eval'ed in `tramp-expand-args'. |
| 618 | (tramp-extra-expand-args | 640 | (tramp-extra-expand-args |
| 619 | . (?a (tramp-kubernetes--container (car tramp-current-connection)) | 641 | . (?a (tramp-kubernetes--container (car tramp-current-connection)) |
| 620 | ?h (tramp-kubernetes--pod (car tramp-current-connection)) | 642 | ?h (tramp-kubernetes--pod (car tramp-current-connection)) |
| 621 | ?x (tramp-kubernetes--context-namespace | 643 | ?x (tramp-kubernetes--context-namespace |
| 622 | (car tramp-current-connection))))) | 644 | (car tramp-current-connection))))) |
| 623 | "Default connection-local variables for remote kubernetes connections.") | 645 | "Default connection-local variables for remote kubernetes connections.") |
| 624 | 646 | ||
| 625 | (connection-local-set-profile-variables | 647 | (connection-local-set-profile-variables |