[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kubed 6c6886bdcd 11/12: New user option 'kubed-default-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/kubed 6c6886bdcd 11/12: New user option 'kubed-default-context-and-namespace' |
Date: |
Thu, 15 Aug 2024 12:58:29 -0400 (EDT) |
branch: externals/kubed
commit 6c6886bdcda13e9c7500ca48205b4f8de0b0daff
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
New user option 'kubed-default-context-and-namespace'
* kubed.el (kubed-default-context-and-namespace): New user
option and function of same name.
(kubed-default-context, kubed-default-namespace): New funcs.
(kubed-local-namespace, kubed-local-context)
(kubed-local-context-and-namespace): Use them. Adjust
calls to 'kubed-local-namespace'.
* kubed.texi (Context and Namespace): New section.
---
kubed.el | 94 +++++++++++++++++++++++++++++++++++++++-----------------------
kubed.texi | 54 ++++++++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+), 35 deletions(-)
diff --git a/kubed.el b/kubed.el
index af67126c53..bcffc23d30 100644
--- a/kubed.el
+++ b/kubed.el
@@ -56,6 +56,16 @@
"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.
+
+This is either a cons cell (CONTEXT . NAMESPACE), or nil. If nil, Kubed
+initializes this option to a non-nil value next time Kubed consults it."
+ :type '(choice (const :tag "Initialize from `kubectl' on first use" nil)
+ (cons :tag "Context and namespace"
+ (string :tag "Context")
+ (string :tag "Namespace"))))
+
(defcustom kubed-yaml-setup-hook '(yaml-ts-mode view-mode)
"List of functions to call in Kubernetes resource description YAML buffers.
@@ -253,7 +263,7 @@ prompt for CONTEXT as well."
nil context)))
(when (and (kubed-namespaced-p type context) (null namespace))
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1034,7 +1044,7 @@ prompt for CONTEXT as well."
nil context)))
(when (and (kubed-namespaced-p type context) (null namespace))
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1100,7 +1110,7 @@ prompt for CONTEXT as well."
nil context)))
(when (and (kubed-namespaced-p type context) (null namespace))
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1283,7 +1293,7 @@ Interactively, use the current context. With a prefix
argument
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil
context)
cur))))
@@ -1303,7 +1313,7 @@ Interactively, use the current context. With a prefix
argument
(let ((context (or context (kubed-local-context))))
(kubed-display-resource
,(symbol-name plrl-var) ,resource context
- . ,(when namespaced '((or namespace (kubed-local-namespace
context)))))))
+ . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
(defun ,edt-name (,resource &optional context . ,(when namespaced
'(namespace)))
,(if namespaced
@@ -1334,7 +1344,7 @@ Interactively, use the current context. With a prefix
argument
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil
context)
cur))))
@@ -1354,7 +1364,7 @@ Interactively, use the current context. With a prefix
argument
(let ((context (or context (kubed-local-context))))
(kubed-edit-resource
,(symbol-name plrl-var) ,resource context
- . ,(when namespaced '((or namespace (kubed-local-namespace
context)))))))
+ . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
(defun ,dlt-name (,plrl-var &optional context
. ,(when namespaced '(namespace)))
@@ -1386,7 +1396,7 @@ Interactively, use the current context. With a prefix
argument
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil
context)
cur))))
@@ -1408,7 +1418,7 @@ Interactively, use the current context. With a prefix
argument
(let ((context (or context (kubed-local-context))))
(kubed-delete-resources
,(symbol-name plrl-var) ,plrl-var context
- . ,(when namespaced '((or namespace (kubed-local-namespace
context)))))))
+ . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
,(if crt-spec `(defun ,crt-name . ,crt-spec)
`(defun ,crt-name (definition &optional context)
@@ -1540,7 +1550,7 @@ Interactively, use the current context. With a prefix
argument
context)))
(list context
. ,(when namespaced
- '((let ((cur (kubed-local-namespace context)))
+ '((let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil
context)
cur)))))))
@@ -1627,6 +1637,7 @@ Interactively, use the current context. With a prefix
argument
;; introduced in Emacs 31. See Bug#59797.
(kubed--static-if (<= 31 emacs-major-version)
(dired (concat "/kubernetes:" pod "%" kubed-list-namespace ":"))
+ ;; FIXME: Also check context.
(unless (string= kubed-list-namespace (kubed-current-namespace))
(if (y-or-n-p
(format "Starting Dired in a pod in a different namespace \
@@ -1790,7 +1801,7 @@ defaulting to the current namespace."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1799,7 +1810,7 @@ defaulting to the current namespace."
(format "Create job `%s' from cronjob" name) nil nil context
namespace)
context namespace)))
(let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context))))
+ (namespace (or namespace (kubed-local-namespace))))
(unless (zerop
(call-process
kubed-kubectl-program nil nil nil
@@ -1846,7 +1857,7 @@ defaulting to the current namespace."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1891,7 +1902,7 @@ NAMESPACE too. With a double prefix argument, also
prompt for CONTEXT."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1900,7 +1911,7 @@ NAMESPACE too. With a double prefix argument, also
prompt for CONTEXT."
context namespace)))
(let ((buf (get-buffer-create "*kubed-deployment-status*"))
(context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context))))
+ (namespace (or namespace (kubed-local-namespace))))
(with-current-buffer buf (erase-buffer))
(make-process
:name "*kubed-watch-deployment-status*"
@@ -1945,7 +1956,7 @@ NAMESPACE too. With a double prefix argument, also
prompt for CONTEXT."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -1953,7 +1964,7 @@ NAMESPACE too. With a double prefix argument, also
prompt for CONTEXT."
context namespace)
context namespace)))
(let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context))))
+ (namespace (or namespace (kubed-local-namespace))))
(unless (zerop
(apply #'call-process
kubed-kubectl-program nil nil nil
@@ -2031,13 +2042,13 @@ optional command to run in the images."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
(list name images context namespace replicas port command)))
(let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context))))
+ (namespace (or namespace (kubed-local-namespace))))
(unless (zerop
(apply #'call-process
kubed-kubectl-program nil nil nil
@@ -2148,7 +2159,7 @@ overrides the default command IMAGE runs."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -2242,7 +2253,7 @@ DEFAULT-BACKEND is the service to use as a backend for
unhandled URLs."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -2283,11 +2294,24 @@ DEFAULT-BACKEND is the service to use as a backend for
unhandled URLs."
"Return current Kubernetes context."
(car (process-lines kubed-kubectl-program "config" "current-context")))
+(defun kubed-default-context-and-namespace ()
+ (or kubed-default-context-and-namespace
+ (setq kubed-default-context-and-namespace
+ (let ((context (kubed-current-context)))
+ (cons context
+ (kubed-current-namespace context))))))
+
+(defun kubed-default-context ()
+ (car (kubed-default-context-and-namespace)))
+
+(defun kubed-default-namespace ()
+ (cdr (kubed-default-context-and-namespace)))
+
(defun kubed-local-context ()
"Return Kubernetes context local to the current buffer."
(or kubed-list-context
(nth 2 kubed-display-resource-info)
- (kubed-current-context)))
+ (kubed-default-context)))
(defvar kubed-context-history nil
"History list for `kubed-read-context'.")
@@ -2360,7 +2384,7 @@ Optional argument DEFAULT is the minibuffer default
argument."
(format "jsonpath={.contexts[?(.name==\"%s\")].context.namespace}"
(or context (kubed-current-context))))))
-(defun kubed-local-namespace (&optional context)
+(defun kubed-local-namespace ()
"Return Kubernetes namespace in CONTEXT local to the current buffer."
(or kubed-list-namespace
(nth 3 kubed-display-resource-info)
@@ -2368,7 +2392,7 @@ Optional argument DEFAULT is the minibuffer default
argument."
(and (string-match "[/|]kubernetes:.*%\\([a-z0-9-]+\\):"
default-directory)
(match-string 1 default-directory)))
- (kubed-current-namespace (or context (kubed-local-context)))))
+ (kubed-default-namespace)))
(defun kubed-local-context-and-namespace ()
"Return (CONTEXT . NAMESPACE) pair local to the current buffer."
@@ -2380,13 +2404,13 @@ Optional argument DEFAULT is the minibuffer default
argument."
(cons context
(or (nth 3 kubed-display-resource-info)
(kubed-current-namespace context))))
- (let ((context (kubed-current-context)))
+ (let ((context (kubed-default-context)))
(cons context
(or (kubed--static-if (<= 31 emacs-major-version)
(and (string-match "[/|]kubernetes:.*%\\([a-z0-9-]+\\):"
default-directory)
(match-string 1 default-directory)))
- (kubed-current-namespace context))))))
+ (kubed-default-namespace))))))
;;;###autoload
(defun kubed-set-namespace (namespace &optional context)
@@ -2399,7 +2423,7 @@ prefix argument, prompt for CONTEXT as well."
(context (if current-prefix-arg
(kubed-read-context "Context" context)
context)))
- (list (kubed-read-namespace "Set namespace" (kubed-local-namespace
context)
+ (list (kubed-read-namespace "Set namespace" (kubed-local-namespace)
nil context)
context)))
(unless (zerop
@@ -2569,7 +2593,7 @@ for NAMESPACE; with a double prefix argument, also prompt
for CONTEXT."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -2668,7 +2692,7 @@ use it; otherwise, fall back to prompting."
(context (if (equal current-prefix-arg '(16))
(kubed-read-context "Context" context)
context))
- (n (kubed-local-namespace context))
+ (n (kubed-local-namespace))
(n (if current-prefix-arg
(kubed-read-namespace "Namespace" n nil context)
n))
@@ -2676,7 +2700,7 @@ use it; otherwise, fall back to prompting."
(c (kubed-read-container p "Container" nil context n)))
(list p c context n)))
(let* ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context)))
+ (namespace (or namespace (kubed-local-namespace)))
(buf (generate-new-buffer
(format "*kubed-logs %s[%s] in %s[%s]*"
pod container namespace context))))
@@ -2708,7 +2732,7 @@ use it; otherwise, fall back to prompting."
(c (if (equal current-prefix-arg '(16))
(kubed-read-context "Context" c)
c))
- (n (kubed-local-namespace c))
+ (n (kubed-local-namespace))
(n (if current-prefix-arg
(kubed-read-namespace "Namespace" n nil c)
n))
@@ -2825,7 +2849,7 @@ STDIN and TTY are t interactively."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -2928,7 +2952,7 @@ STDIN and TTY are t interactively."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -2988,7 +3012,7 @@ for CONTEXT."
cxt))))
(unless namespace
(setq namespace
- (let ((cur (kubed-local-namespace context)))
+ (let ((cur (kubed-local-namespace)))
(if current-prefix-arg
(kubed-read-namespace "Namespace" cur nil context)
cur))))
@@ -3036,7 +3060,7 @@ resource types."
(defun kubed-resource-names (type &optional context namespace)
"Return list of Kuberenetes resources of type TYPE in NAMESPACE via CONTEXT."
(let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace context))))
+ (namespace (or namespace (kubed-local-namespace))))
(unless (kubed--alist type context namespace)
(let ((proc (kubed-update type context namespace)))
(while (process-live-p proc)
diff --git a/kubed.texi b/kubed.texi
index bc5904571c..b7f972ac36 100644
--- a/kubed.texi
+++ b/kubed.texi
@@ -174,6 +174,7 @@ The following sections describe in detail the various Kubed
commands.
@menu
* Display Resource::
* Browse Resources::
+* Context and Namespace::
* Transient Menus::
@end menu
@@ -202,6 +203,8 @@ this command assumes you want to display a resource that is
in the
current namespace, but if you invoke @code{kubed-display-resource}
with a prefix argument (@kbd{C-u}) and choose a namespaced resource
type, then it also lets you select the namespace of the resource.
+With a double prefix argument, it lets you select which
+@command{kubectl} context to use too. @xref{Context and Namespace}.
If you have @code{kubed-prefix-map} bound to @kbd{C-c k}, you can
invoke @code{kubed-display-resource} with @kbd{C-c k @key{RET}}. This
@@ -512,6 +515,57 @@ While entering a filter in the minibuffer, @kbd{@key{TAB}}
completion
is available for column names and values. To clear the filter, just
exit the minibuffer with an empty input.
+@node Context and Namespace
+@section Context and Namespace
+
+Kubed uses @command{kubectl} to interact with Kubernetes clusters, and
+you can use multiple @command{kubectl} @dfn{contexts} in Kubed to work
+with different Kubernetes clusters in parallel. Within each context,
+Kubed lets you work in multiple @dfn{namespaces} too. In general,
+each buffer has its own @dfn{local context} and @dfn{local namespace},
+and Kubed commands use these local context and namespace by default.
+This is similar to how different buffers have different values of
+@code{default-directory} (@pxref{File Names,,,emacs}), and how that
+affects commands that interact with the filesystem.
+
+For Kubed buffers that display a Kubernetes resource (@pxref{Display
+Resource}) or a list of resources (@pxref{Browse Resources}), the
+buffer-local context and namespace are the context and namespace of
+the resources the buffer displays. For non-Kubed buffers, the user
+option @code{kubed-default-context-and-namespace} determines the
+default local context and namespace.
+
+@defopt kubed-default-context-and-namespace
+Default @command{kubectl} context and Kubernetes namespace for Kubed
+commands. The value of this option is either a cons cell
+@w{@code{(@var{context} . @var{namespace})}} or @code{nil}. If it is
+@code{nil}, Kubed initializes this option to a cons cell with the
+current @command{kubectl} context and namespace for that context on
+the first time Kubed consults this option.
+@end defopt
+
+As mentioned above, most Kubed commands use the local context and
+namespace by default---it is also conventional for Kubed commands to
+let you choose a different namespace if you invoke them with a prefix
+argument (@kbd{C-u}), and to also let you choose a different context
+if you invoke them with a double prefix argument (@kbd{C-u C-u}).
+
+The following functions return the local context and namespace for
+buffer in which you call them:
+
+@defun kubed-local-context
+Return the local @command{kubectl} context for the current buffer.
+@end defun
+
+@defun kubed-local-namespace
+Return the local Kubernetes namespace for the current buffer.
+@end defun
+
+@defun kubed-local-context-and-namespace
+Return the local context and namespace for the current buffer as a
+cons cell @w{@code{(@var{context} . @var{namespace})}}.
+@end defun
+
@node Transient Menus
@section Transient Menus
- [elpa] externals/kubed updated (cca5f42891 -> 0863c58f1a), ELPA Syncer, 2024/08/15
- [elpa] externals/kubed a46344f2b0 01/12: Use buffer-local context in 'kubed-list-*' commands, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed cdeb94ea56 03/12: ; Use local context as default in some prompts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed a1c741360a 08/12: Teach 'kubed-exec' about buffer-local contexts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 003ecf531c 04/12: Teach rollout commands about buffer-local contexts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 6c6886bdcd 11/12: New user option 'kubed-default-context-and-namespace',
ELPA Syncer <=
- [elpa] externals/kubed 72593fb84f 02/12: ; (kubed-current-namespace): Use buffer-local context., ELPA Syncer, 2024/08/15
- [elpa] externals/kubed ae4ba0de59 10/12: Teach additional commands about buffer-local contexts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 5b2f47142a 06/12: Teach 'kubed-patch' about buffer-local contexts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed e545b90c54 05/12: ; (kubed-resource-names): Default to local context and namespace, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 5954f4f339 09/12: ; Fix regex matching multi-hop Tramp file names, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 5cb64af942 07/12: Teach 'kubed-diff' about buffer-local contexts, ELPA Syncer, 2024/08/15
- [elpa] externals/kubed 0863c58f1a 12/12: ; Update NEWS.org and bump version to 0.3.2, ELPA Syncer, 2024/08/15