From: Eshel Yaron Date: Thu, 14 Aug 2025 20:19:50 +0000 (+0200) Subject: ; Refine last change. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=774bdf6ede902f0c274f2de7f52ce7ea7fedea05;p=kubed.git ; Refine last change. * kubed.el (kubed-use-context): Always set the namespace part of 'kubed-default-context-and-namespace' to non-nil. (kubed-set-namespace): Update docstring. * NEWS.org: Announce change. --- diff --git a/NEWS.org b/NEWS.org index c8dd79a..b6c8073 100644 --- a/NEWS.org +++ b/NEWS.org @@ -10,6 +10,14 @@ for Kubernetes. For further details, see the Kubed manual: [[https://eshelyaron.com/kubed.html][https://eshelyaron.com/kubed.html]]. +* Version 0.5.1 in development + +** ~kubed-use-context~ now also updates ~kubed-default-context-and-namespace~ + +Setting the default ~kubectl~ context with ~kubed-use-context~ now +also updates the user option ~kubed-default-context-and-namespace~, +such that Kubed commands will also use the new context as a default. + * Version 0.5.0 on 2025-06-11 ** DaemonSets support diff --git a/kubed.el b/kubed.el index 6bc7731..d5c3cbc 100644 --- a/kubed.el +++ b/kubed.el @@ -2508,7 +2508,10 @@ Optional argument DEFAULT is the minibuffer default argument." ;;;###autoload (defun kubed-use-context (context) - "Set current Kubernetes context and default context to CONTEXT. + "Set default `kubectl' context to CONTEXT. + +This command sets the global `kubectl' default context, and updates the +value of user option `kubed-default-context-and-namespace' accordingly. Interactively, prompt for CONTEXT with completion." (interactive @@ -2518,8 +2521,12 @@ Interactively, prompt for CONTEXT with completion." kubed-kubectl-program nil nil nil "config" "use-context" context)) (user-error "Failed to use Kubernetes context `%s'" context)) - (setq kubed-default-context-and-namespace (list context)) - (message "Now using Kubernetes context `%s'." context)) + (let ((namespace (or (kubed-current-namespace context) + (kubed-read-namespace + (format "Default namespace to use in context `%s'" context) + nil nil context)))) + (setq kubed-default-context-and-namespace (cons context namespace)) + (message "Default context is now `%s', namespace `%s'." context namespace))) ;;;###autoload (defun kubed-rename-context (old new) @@ -2598,6 +2605,10 @@ If no namespace is configured for CONTEXT, return nil." (defun kubed-set-namespace (namespace &optional context) "Set default Kubernetes namespace in CONTEXT to NAMESPACE. +If CONTEXT is the current default context, also update the value of user +option `kubed-default-context-and-namespace' to use NAMESPACE as the +default namespace. + Interactively, prompt for NAMESPACE and use the current context. With a prefix argument, prompt for CONTEXT as well." (interactive