branch: externals/kubed
commit 774bdf6ede902f0c274f2de7f52ce7ea7fedea05
Author: Eshel Yaron <m...@eshelyaron.com>
Commit: Eshel Yaron <m...@eshelyaron.com>

    ; 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.
---
 NEWS.org |  8 ++++++++
 kubed.el | 17 ++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index c8dd79adbe..b6c8073ba6 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 6bc7731836..d5c3cbce4c 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

Reply via email to