From 1480199df68fd428381144b2e1d9474480d99cb1 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 27 Jul 2024 20:47:10 +0200 Subject: [PATCH] New commands 'kubed-rename-context' and 'kubed-display-config' --- lisp/net/kubed.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lisp/net/kubed.el b/lisp/net/kubed.el index d18da0bdcf1..6e8f0cf2088 100644 --- a/lisp/net/kubed.el +++ b/lisp/net/kubed.el @@ -1258,6 +1258,46 @@ Optional argument DEFAULT is the minibuffer default argument." (message "Now using Kubernetes context `%s'." context) (kubed-update-all)) +;;;###autoload +(defun kubed-rename-context (old new) + "Rename Kubernetes context OLD to NEW." + (interactive + (let ((old (kubed-read-context "Rename context" (kubed-current-context)))) + (list old (read-string (format-prompt "Rename context to" old) + nil 'kubed-context-history old)))) + (unless (zerop + (call-process + kubed-kubectl-program nil nil nil + "config" "rename-context" old new)) + (user-error "Failed to rename Kubernetes context `%s' to `%s'" old new)) + (message "Renamed Kubernetes context `%s' to `%s'." old new)) + +;;;###autoload +(defun kubed-display-config () + "Display current Kubernetes client settings in a YAML buffer." + (interactive) + (let* ((buf (get-buffer-create "*kubed-config*")) + (fun (lambda (&optional _ _) + (let ((inhibit-read-only t) + (target (current-buffer))) + (buffer-disable-undo) + (with-temp-buffer + (unless (zerop + (call-process + kubed-kubectl-program nil t nil "config" "view")) + (error "`kubectl config view'")) + (let ((source (current-buffer))) + (with-current-buffer target + (replace-buffer-contents source) + (set-buffer-modified-p nil) + (buffer-enable-undo)))))))) + (with-current-buffer buf + (funcall fun) + (goto-char (point-min)) + (run-hooks 'kubed-yaml-setup-hook) + (setq-local revert-buffer-function fun)) + (display-buffer buf))) + (defun kubed-current-namespace (&optional context) "Return current Kubernetes namespace for context CONTEXT." (car (process-lines -- 2.39.2