emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/kubed 003ecf531c 04/12: Teach rollout commands about bu


From: ELPA Syncer
Subject: [elpa] externals/kubed 003ecf531c 04/12: Teach rollout commands about buffer-local contexts
Date: Thu, 15 Aug 2024 12:58:28 -0400 (EDT)

branch: externals/kubed
commit 003ecf531c6948ba3cbef9d58dac4552caa9d74b
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    Teach rollout commands about buffer-local contexts
    
    * kubed-transient.el (kubed-transient-rollout): Add
    "--context" infix argument.
    * kubed.el (kubed-restart-deployment)
    (kubed-watch-deployment-status): Use local context and
    namespace.  Also add callback argument to 'watch' command.
---
 kubed-transient.el |   4 +-
 kubed.el           | 117 ++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 84 insertions(+), 37 deletions(-)

diff --git a/kubed-transient.el b/kubed-transient.el
index 1dcf918095..2b03ffb419 100644
--- a/kubed-transient.el
+++ b/kubed-transient.el
@@ -75,7 +75,9 @@
     ("!" "Command line" kubed-kubectl-command)]
    ["Options"
     ("-n" "Namespace" "--namespace="
-     :prompt "Namespace" :reader kubed-transient-read-namespace)]]
+     :prompt "Namespace" :reader kubed-transient-read-namespace)
+    ("-C" "Context" "--context="
+     :prompt "Context" :reader kubed-transient-read-context)]]
   (interactive)
   (transient-setup 'kubed-transient-rollout nil nil
                    :scope '("rollout")))
diff --git a/kubed.el b/kubed.el
index d96fa8121f..558aeb29db 100644
--- a/kubed.el
+++ b/kubed.el
@@ -1865,35 +1865,53 @@ defaulting to the current namespace."
    (message "Created Kubernetes job `%s'." name)))
 
 ;;;###autoload
-(defun kubed-watch-deployment-status (dep &optional context namespace)
+(defun kubed-watch-deployment-status (dep &optional context namespace cb)
   "Show and update status of Kubernetes deployment DEP in a dedicate buffer.
 
 Optional argument CONTEXT is the `kubectl' context to use, defaulting to
 the current context; NAMESPACE is the namespace of DEP, defaulting to
-the current namespace."
+the current namespace.  CB is an optional callback function to call with
+no arguments when the deployment ends.
+
+Interactively, prompt for DEP.  With a prefix argument, prompt for
+NAMESPACE too.  With a double prefix argument, also prompt for CONTEXT."
   (interactive
-   (let ((namespace (seq-some
-                     (lambda (arg)
-                       (when (string-match "--namespace=\\(.+\\)" arg)
-                         (match-string 1 arg)))
-                     (kubed-transient-args 'kubed-transient-rollout))))
-     (list (kubed-read-deployment "Watch deployment status" nil nil nil 
namespace)
-           nil namespace)))
+   (let (context namespace)
+     (dolist (arg (kubed-transient-args 'kubed-transient-rollout))
+       (cond
+        ((string-match "--context=\\(.+\\)" arg)
+         (setq context (match-string 1 arg)))
+        ((string-match "--namespace=\\(.+\\)" arg)
+         (setq namespace (match-string 1 arg)))))
+     (unless context
+       (setq context
+             (let ((cxt (kubed-local-context)))
+               (if (equal current-prefix-arg '(16))
+                   (kubed-read-context "Context" cxt)
+                 cxt))))
+     (unless namespace
+       (setq namespace
+             (let ((cur (kubed-local-namespace context)))
+               (if current-prefix-arg
+                   (kubed-read-namespace "Namespace" cur nil context)
+                 cur))))
+     (list (kubed-read-deployment "Watch deployment status" nil nil
+                                  context namespace)
+           context namespace)))
   (let ((buf (get-buffer-create "*kubed-deployment-status*"))
-        (context (or context (kubed-current-context)))
-        (namespace (or namespace (kubed-current-namespace context))))
+        (context (or context (kubed-local-context)))
+        (namespace (or namespace (kubed-local-namespace context))))
     (with-current-buffer buf (erase-buffer))
     (make-process
      :name "*kubed-watch-deployment-status*"
      :buffer buf
      :command (list kubed-kubectl-program "rollout" "status"
                     "deployment" dep "-n" namespace "--context" context)
-     :sentinel
-     (lambda (_proc status)
-       (when (member status
-                     '("finished\n" "exited abnormally with code 1\n"))
-         (message "Deployment complete")
-         (kubed-update "deployments" context namespace))))
+     :sentinel (when cb
+                 (lambda (_proc status)
+                   (when (member status '("finished\n"
+                                          "exited abnormally with code 1\n"))
+                     (funcall cb)))))
     (display-buffer buf)))
 
 (defcustom kubed-restart-deployment-watch-status t
@@ -1903,26 +1921,53 @@ the current namespace."
 ;;;###autoload
 (defun kubed-restart-deployment (dep &optional context namespace)
   "Restart Kubernetes deployment DEP in namespace NAMESPACE via CONTEXT.
-If NAMESPACE is nil or omitted, it defaults to the current namespace."
+
+Optional argument CONTEXT is the `kubectl' context to use, defaulting to
+the current context; NAMESPACE is the namespace of DEP, defaulting to
+the current namespace.  CB is an optional callback function to call with
+no arguments when the deployment ends.
+
+Interactively, prompt for DEP.  With a prefix argument, prompt for
+NAMESPACE too.  With a double prefix argument, also prompt for CONTEXT."
   (interactive
-   (let ((namespace (seq-some
-                     (lambda (arg)
-                       (when (string-match "--namespace=\\(.+\\)" arg)
-                         (match-string 1 arg)))
-                     (kubed-transient-args 'kubed-transient-rollout))))
-     (list (kubed-read-deployment "Restart deployment" nil nil nil namespace)
-           nil namespace)))
-  (unless (zerop
-           (apply #'call-process
-                  kubed-kubectl-program nil nil nil
-                  "rollout" "restart" "deployment" dep
-                  (append
-                   (when namespace (list "-n" namespace))
-                   (when context (list "--context" context)))))
-    (user-error "Failed to restart Kubernetes deployment `%s'" dep))
-  (message "Restarting Kubernetes deployment `%s'." dep)
-  (when kubed-restart-deployment-watch-status
-    (kubed-watch-deployment-status dep context namespace)))
+   (let (context namespace)
+     (dolist (arg (kubed-transient-args 'kubed-transient-rollout))
+       (cond
+        ((string-match "--context=\\(.+\\)" arg)
+         (setq context (match-string 1 arg)))
+        ((string-match "--namespace=\\(.+\\)" arg)
+         (setq namespace (match-string 1 arg)))))
+     (unless context
+       (setq context
+             (let ((cxt (kubed-local-context)))
+               (if (equal current-prefix-arg '(16))
+                   (kubed-read-context "Context" cxt)
+                 cxt))))
+     (unless namespace
+       (setq namespace
+             (let ((cur (kubed-local-namespace context)))
+               (if current-prefix-arg
+                   (kubed-read-namespace "Namespace" cur nil context)
+                 cur))))
+     (list (kubed-read-deployment "Restart deployment" nil nil
+                                  context namespace)
+           context namespace)))
+  (let ((context (or context (kubed-local-context)))
+        (namespace (or namespace (kubed-local-namespace context))))
+    (unless (zerop
+             (apply #'call-process
+                    kubed-kubectl-program nil nil nil
+                    "rollout" "restart" "deployment" dep
+                    (append
+                     (when namespace (list "-n" namespace))
+                     (when context (list "--context" context)))))
+      (user-error "Failed to restart Kubernetes deployment `%s'" dep))
+    (message "Restarting Kubernetes deployment `%s'." dep)
+    (when kubed-restart-deployment-watch-status
+      (kubed-watch-deployment-status
+       dep context namespace
+       (lambda ()
+         (kubed-update "deployments" context namespace))))))
 
 ;;;###autoload (autoload 'kubed-display-deployment "kubed" nil t)
 ;;;###autoload (autoload 'kubed-edit-deployment "kubed" nil t)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]