]> git.eshelyaron.com Git - emacs.git/commitdiff
New commands 'kubed{-transient}-apply'
authorEshel Yaron <me@eshelyaron.com>
Sat, 27 Jul 2024 12:22:58 +0000 (14:22 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 27 Jul 2024 12:22:58 +0000 (14:22 +0200)
lisp/net/kubed-transient.el
lisp/net/kubed.el

index d43594eb33d57067494a2b3a71d9c24496f7bd6d..5031869877bfc245b922668119b4cd5dd037ac7d 100644 (file)
 (transient-define-prefix kubed-transient ()
   "Perform Kubernetes operation."
   ["Actions"
-   ("c" "Create" kubed-transient-create)
-   ("r" "Run" kubed-transient-run)
-   ("a" "Attach" kubed-transient-attach)
-   ("d" "Diff" kubed-transient-diff)
-   ("e" "Exec" kubed-transient-exec)
+   ("+" "Create"  kubed-transient-create)
+   ("*" "Apply"   kubed-transient-apply)
+   ("r" "Run"     kubed-transient-run)
+   ("a" "Attach"  kubed-transient-attach)
+   ("d" "Diff"    kubed-transient-diff)
+   ("e" "Exec"    kubed-transient-exec)
    ("E" "Explain" kubed-explain)
    ("!" "Command line" kubed-kubectl-command)])
 
   (transient-setup 'kubed-transient-create nil nil
                    :scope '("create")))
 
+;;;###autoload
+(transient-define-prefix kubed-transient-apply ()
+  "Apply configuration to Kubernetes resource."
+  ["Options"
+   ("-f" "Definition file" "--filename="
+    :reader kubed-transient-read-resource-definition-file-name)]
+  ["Actions"
+   ("*" "apply" kubed-apply)
+   ("!" "Command line" kubed-kubectl-command)]
+  (interactive)
+  (transient-setup 'kubed-transient-apply nil nil
+                   :scope '("apply")))
+
 ;;;###autoload
 (transient-define-prefix kubed-transient-create-deployment ()
   "Create Kubernetes deployment."
index 9500733db199ea7e2891171ce8b87389f418e9a6..93601a780741e71eae281ba6cdcb72813afee3bc 100644 (file)
@@ -1210,6 +1210,22 @@ completion candidates."
              (member (substring f (1+ (match-beginning 0)))
                      '("yaml" "yml" "json"))))))))
 
+;;;###autoload
+(defun kubed-apply (config &optional kind)
+  "Apply CONFIG to Kubernetes resource of kind KIND."
+  (interactive
+   (list (or (seq-some
+              (lambda (arg)
+                (when (string-match "--filename=\\(.+\\)" arg)
+                  (match-string 1 arg)))
+              (kubed-transient-args 'kubed-transient-apply))
+             (kubed-read-resource-definition-file-name))))
+  (let ((kind (or kind "resource")))
+    (message "Applying Kubernetes %s configuration `%s'..." kind config)
+    (call-process kubed-kubectl-program nil nil nil
+                  "apply" "-f" (expand-file-name config))
+    (message "Applying Kubernetes %s configuration `%s'... Done." kind config)))
+
 ;;;###autoload
 (defun kubed-create (definition &optional kind)
   "Create Kubernetes resource of kind KIND with definition DEFINITION."
@@ -1714,8 +1730,9 @@ Interactively, prompt for COMMAND with completion for `kubectl' arguments."
   "U" #'kubed-update-all
   "A" #'kubed-all-namespaces-mode
   "+" #'kubed-create
+  "*" #'kubed-apply
   "R" #'kubed-run
-  "D" #'kubed-diff
+  "=" #'kubed-diff
   "E" #'kubed-explain
   "!" #'kubed-kubectl-command)