]> git.eshelyaron.com Git - kubed.git/commitdiff
; Refine last change. master
authorEshel Yaron <me@eshelyaron.com>
Thu, 14 Aug 2025 20:19:50 +0000 (22:19 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 14 Aug 2025 20:19:50 +0000 (22:19 +0200)
* 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
kubed.el

index c8dd79adbe817d2d4060728ff17e046045037220..b6c8073ba6fc4c5b6095d08f89675f0b6d6bf412 100644 (file)
--- 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]].
 
 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
 * Version 0.5.0 on 2025-06-11
 
 ** DaemonSets support
index 6bc77318363ac1f02c7f3c42504ee857d13da9dc..d5c3cbce4cba49ce4c6ef4efa99c2651c2373c9c 100644 (file)
--- a/kubed.el
+++ b/kubed.el
@@ -2508,7 +2508,10 @@ Optional argument DEFAULT is the minibuffer default argument."
 
 ;;;###autoload
 (defun kubed-use-context (context)
 
 ;;;###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
 
 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))
             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)
 
 ;;;###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.
 
 (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
 Interactively, prompt for NAMESPACE and use the current context.  With a
 prefix argument, prompt for CONTEXT as well."
   (interactive