From: Eshel Yaron Date: Thu, 25 Jul 2024 20:33:12 +0000 (+0200) Subject: New commands 'kubed{-transient}-diff' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d1f74afd94990c5aceef12209e69ff2447898bd6;p=emacs.git New commands 'kubed{-transient}-diff' --- diff --git a/lisp/net/kubed-transient.el b/lisp/net/kubed-transient.el index 010630942d8..cb91e3fa3b1 100644 --- a/lisp/net/kubed-transient.el +++ b/lisp/net/kubed-transient.el @@ -46,6 +46,7 @@ ("c" "Create" kubed-transient-create) ("r" "Run" kubed-transient-run) ("a" "Attach" kubed-transient-attach) + ("d" "Diff" kubed-transient-diff) ("!" "Command line" kubed-kubectl-command)]) ;;;###autoload @@ -65,6 +66,21 @@ :value '("--stdin") :scope '("attach"))) +;;;###autoload +(transient-define-prefix kubed-transient-diff () + "Display difference between Kubernetes resource definition and current state." + ["Switches" + ("-M" "Include managed fields" "--show-managed-fields")] + ["Options" + ("-f" "Definition file" "--filename=" + :reader kubed-transient-read-resource-definition-file-name)] + ["Actions" + ("d" "Diff" kubed-diff) + ("!" "Command line" kubed-kubectl-command)] + (interactive) + (transient-setup 'kubed-transient-diff nil nil + :scope '("diff"))) + ;;;###autoload (transient-define-prefix kubed-transient-run () "Run container image in a Kubernetes pod." diff --git a/lisp/net/kubed.el b/lisp/net/kubed.el index 12ce8a8de42..c43d94b2783 100644 --- a/lisp/net/kubed.el +++ b/lisp/net/kubed.el @@ -1383,6 +1383,37 @@ Non-nil TTY says to use a TTY for standard input." (when stdin '("-i")) (when tty '("-t")))))) +;;;###autoload +(defun kubed-diff (definition &optional include-managed) + "Display difference between Kubernetes resource DEFINITION and current state. + +Non-nil optional argument INCLUDE-MANAGED (interactively, the prefix +argument) says to include managed fields in the comparison." + (interactive + (let ((definition nil) (include-managed nil)) + (dolist (arg (when (and (fboundp 'transient-args) + (fboundp 'kubed-transient-diff)) + (transient-args 'kubed-transient-diff))) + (cond + ((string-match "--filename=\\(.+\\)" arg) + (setq definition (match-string 1 arg))) + ((equal "--show-managed-fields" arg) (setq include-managed t)))) + (list (or definition (kubed-read-resource-definition-file-name)) + (or include-managed current-prefix-arg)))) + (let ((buf (get-buffer-create "*kubed-diff*"))) + (with-current-buffer buf + (setq buffer-read-only nil) + (delete-region (point-min) (point-max)) + (fundamental-mode) + (call-process kubed-kubectl-program nil t nil "diff" + (concat "--show-managed-fields=" + (if include-managed "true" "false")) + "-f" (expand-file-name definition)) + (setq buffer-read-only t) + (diff-mode) + (goto-char (point-min))) + (display-buffer buf))) + (defvar kubed-kubectl-command-history nil "Minibuffer history for `kubed-kubectl-command'.") @@ -1424,9 +1455,11 @@ Interactively, prompt for COMMAND with completion for `kubectl' arguments." "j" 'kubed-job-prefix-map "d" 'kubed-deployment-prefix-map "C" #'kubed-use-context + "U" #'kubed-update-all "A" #'kubed-all-namespaces-mode "+" #'kubed-create "R" #'kubed-run + "D" #'kubed-diff "@" #'kubed-attach "!" #'kubed-kubectl-command)