Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide kubel-kill-buffer command. #134

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions kubel.el
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ with information about the shell's connection. The following
:type 'string
:group 'kubel)

(defcustom kubel-kill-buffer-query t
"Non-nil means that killing a modified resource buffer has to be confirmed.
This is used by `kubel-kill-buffer'."
:type 'boolean
:group 'kubel)

(defun kubel--append-to-process-buffer (str)
"Append string STR to the process buffer."
(with-current-buffer (get-buffer-create kubel--process-buffer)
Expand Down Expand Up @@ -590,12 +596,13 @@ NAME is the string name of the resource to decribe.
DESCRIBE is boolean to describe instead of get resource details"
(let* ((resource (kubel--select-resource name))
(process-name (format "kubel - %s - %s" name resource))
(callback (lambda () (goto-char (point-min)))))
(callback (lambda ()
(set-buffer-modified-p nil)
(goto-char (point-min)))))
(if describe
(kubel--exec process-name (list "describe" name resource) nil callback)
(kubel--exec process-name (list "get" name "-o" kubel-output resource) nil callback))
(when (string-equal kubel-output "yaml")
(yaml-mode)
(kubel-yaml-editing-mode))))

(defun kubel--show-rollout-revision (type name)
Expand Down Expand Up @@ -640,15 +647,29 @@ TYPENAME is the resource type/name."
(-contains? '("ReplicaSets" "replicasets" "replicasets.apps") kubel-resource)
(-contains? '("StatefulSets" "statefulsets" "statefulsets.apps") kubel-resource)))

(defun kubel-kill-buffer ()
"Kill the current buffer."
(interactive)
(when (or (not (buffer-modified-p))
(not kubel-kill-buffer-query)
(yes-or-no-p "Resource modified; kill anyway? "))
(kill-buffer (current-buffer))))

(defvar kubel-yaml-editing-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'kubel-apply)
(define-key map (kbd "C-c C-k") #'kubel-kill-buffer)
map)
"Keymap used in `kubel-yaml-editing-mode' buffers.")

;; interactive
;;;###autoload
(define-minor-mode kubel-yaml-editing-mode
(define-derived-mode kubel-yaml-editing-mode yaml-mode "kubel/e"
"Kubel Yaml editing mode.
Use C-c C-c to kubectl apply the current yaml buffer."
:init-value nil
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'kubel-apply)
map))

Allows simple apply of the changes made.

\\{kubel-yaml-editing-map}")

(defun kubel-apply ()
"Save the current buffer to a temp file and try to kubectl apply it."
Expand Down Expand Up @@ -679,12 +700,13 @@ Use C-c C-c to kubectl apply the current yaml buffer."
(ns kubel-namespace)
(res kubel-resource)
(process-name (format "kubel - %s - %s" kubel-resource resource))
(callback (lambda () (goto-char (point-min)))))
(callback (lambda ()
(set-buffer-modified-p nil)
(goto-char (point-min)))))
(if describe
(kubel--exec process-name (list "describe" kubel-resource (kubel--get-resource-under-cursor)) nil callback)
(kubel--exec process-name (list "get" kubel-resource (kubel--get-resource-under-cursor) "-o" kubel-output) nil callback))
(when (or (string-equal kubel-output "yaml") (transient-args 'kubel-describe-popup))
(yaml-mode)
(kubel-yaml-editing-mode)
(setq kubel-context ctx)
(setq kubel-namespace ns)
Expand Down