For further details, see the Kubed manual:
[[https://eshelyaron.com/sweep.html][https://eshelyaron.com/kubed.html]].
+* Version 0.3.2 in development
+
+** New filter operators ~<~ and ~>~ in resource tables.
+
+These operators let you filter line with columns that are less than or
+greater than a given value.
+
+** New command for applying changes to displayed resource.
+
+You can now edit displayed resource YAML buffers after you select a
+resource with ~RET~ in the table buffer, and apply your changes to the
+live resource with ~C-c C-c~.
+
* Version 0.3.1 on 2024-08-06
** New command for fitting column width to content in resource tables.
(when namespace (list namespace)))
(kubed-list-go-to-line name)))
+(defun kubed-display-resource-diff ()
+ "Show diff of current buffer with current state of the displayed resource."
+ (interactive)
+ (kubed-diff (current-buffer) nil (nth 2 kubed-display-resource-info)))
+
+(defun kubed-display-resource-replace ()
+ "Replace displayed Kubernetes resource with current buffer contents."
+ (interactive)
+ (let (choice)
+ (while (= ?d (setq choice
+ (car (read-multiple-choice
+ "Replace resource with changes in current buffer?"
+ '((?y "yes") (?n "no") (?d "diff"))))))
+ (kubed-display-resource-diff))
+ (when (= ?y choice)
+ (let ((err-buf (get-buffer-create " *kubed-replace*")))
+ (with-current-buffer err-buf (erase-buffer))
+ (unless (zerop (call-process-region nil nil kubed-kubectl-program
+ nil err-buf nil "replace" "-f" "-"))
+ (display-buffer err-buf)
+ (user-error "`kubectl replace' failed!")))
+ (message "Replaced Kubernetes resource with changes in current buffer.")
+ (revert-buffer))))
+
(defun kubed-display-resource-p (_symbol buffer)
"Return non-nil if `kubed-display-resource-mode' is enabled in BUFFER.
should only be available in buffers that display Kuberenetes resources."
(buffer-local-value 'kubed-display-resource-mode buffer))
-(put 'kubed-display-resource-jump-to-list 'completion-predicate
- #'kubed-display-resource-p)
+(dolist (cmd '(kubed-display-resource-jump-to-list
+ 'kubed-display-resource-diff
+ 'kubed-display-resource-replace))
+ (put cmd 'completion-predicate #'kubed-display-resource-p))
(defvar-keymap kubed-display-resource-mode-map
:doc "Keymap buffers that display Kubernetes resource."
- "C-c C-j" #'kubed-display-resource-jump-to-list)
+ "C-c C-j" #'kubed-display-resource-jump-to-list
+ "C-c C-=" #'kubed-display-resource-diff
+ "C-c C-c" #'kubed-display-resource-replace)
(define-minor-mode kubed-display-resource-mode
"Minor mode for buffers that display a Kuberenetes resource."
(unless (zerop
(call-process
kubed-kubectl-program nil t nil "config" "view"))
- (error "`kubectl config view'"))
+ (error "`kubectl config view' failed"))
(let ((source (current-buffer)))
(with-current-buffer target
(replace-buffer-contents source)
(defun kubed-diff (definition &optional include-managed context)
"Display difference between Kubernetes resource DEFINITION and current state.
+DEFINITION is either a file name or a buffer. Interactively, prompt for
+a YAML or JSON file name to use as DEFINITION.
+
Optional argument CONTEXT is the `kubectl' context to use, defaulting to
the current context; non-nil INCLUDE-MANAGED (interactively, the prefix
argument) says to include managed fields in the comparison."
(list (or definition (kubed-read-resource-definition-file-name))
(or include-managed current-prefix-arg)
context)))
- (let ((buf (get-buffer-create "*kubed-diff*")))
+ (let ((buf (get-buffer-create "*kubed-diff*"))
+ (args (cons "diff"
+ (append
+ (when context (list "--context" context))
+ (when include-managed
+ (list "--show-managed-fields" "true"))
+ (list "-f" (if (bufferp definition) "-"
+ (expand-file-name definition)))))))
(with-current-buffer buf
(setq buffer-read-only nil)
(delete-region (point-min) (point-max))
(fundamental-mode)
- (apply #'call-process kubed-kubectl-program nil t nil "diff"
- (concat "--show-managed-fields="
- (if include-managed "true" "false"))
- "-f" (expand-file-name definition)
- (when context (list "--context" context)))
+ (if (bufferp definition)
+ (with-current-buffer definition
+ (apply #'call-process-region nil nil kubed-kubectl-program
+ nil buf nil args))
+ (apply #'call-process kubed-kubectl-program
+ nil t nil args))
(setq buffer-read-only t)
(diff-mode)
(goto-char (point-min)))
@code{kubed-display-resource-jump-to-list}, which pops up the
resources list buffer for the type of the displayed resource, and
takes you to the line corresponding to it.
+@item
+@kindex C-c C-c
+@findex kubed-display-resource-replace
+@kindex C-c C-=
+@findex kubed-display-resource-diff
+@kindex C-x C-q
+@findex read-only-mode
+It binds @kbd{C-c C-c} to command
+@code{kubed-display-resource-replace}, which lets you apply any
+changes that you make in the YAML buffer back to the resource. When
+you hit @kbd{C-c C-c}, Kubed asks you for confirmation before
+proceeding; you can reply with @kbd{d} (@samp{diff}) to show a diff
+between the current state of the resource and the current buffer
+contents. You can also display this diff anytime with @kbd{C-c C-=}.
+Note that by default Kubed displays resources in read-only buffers, so
+you may need to hit @kbd{C-x C-q} (@code{read-only-mode}) before
+making changes in the buffer.
+@item
+@kindex C-x x g
+@findex revert-buffer
+@findex revert-buffer-quick
+It lets you repopulate the buffer with updated information about the
+resource with @kbd{C-x x g} (@code{revert-buffer-quick}) and
+@w{@kbd{M-x revert-buffer}}. This is also useful if you edit the
+resource and want to restart from a clean slate.
@end itemize
@node Browse Resources