dotfiles/emacs/.emacs.d/config/init-kubernetes.el

62 lines
2.3 KiB
EmacsLisp
Raw Normal View History

2021-02-27 04:55:06 +00:00
;; -*- lexical-binding: t; -*-
(use-package kubectl
:straight (:host github :repo "jypma/kubectl")
:if (executable-find "kubectl")
:config
(setq kubectl--kubectl (executable-find "kubectl"))
(defun kubectl-choose-context (context)
"Select a new context interactively"
(interactive (list (completing-read "Context: " (kubectl--context-names) nil t)))
(setq kubectl--context context)
(make-process :name "kubectx" :command (list (executable-find "kubectx") context))
(call-interactively 'kubectl-choose-namespace))
(defun kubectl-choose-namespace (namespace)
"Select a new namespace interactively"
(interactive (list (completing-read "Namespace: " (kubectl--namespace-names) nil t)))
(setq kubectl--namespace namespace)
(make-process :name "kubens" :command (list (executable-find "kubens") namespace))
(when kubectl-pods-mode
(call-interactively #'kubectl-pods-refresh)))
(general-def kubectl-log-mode-map
"C-c k" #'kubectl--log-kill-process)
(general-def 'normal kubectl-log-mode-map
"q" #'bury-buffer)
(general-def 'normal kubectl-pods-mode-map
"c" #'kubectl-choose-context
"s" #'kubectl-pods-choose-namespace
"gr" #'kubectl-pods-refresh
"gl" #'kubectl--pods-log
"t" #'kubectl--pods-term
"r" #'kubectl-pods-run
"i" #'kubectl--pods-inspect
"d" #'kubectl--pods-dired)
(general-def 'normal kubectl-deployments-mode-map
"c" #'kubectl-choose-context
"s" #'kubectl-choose-namespace
"gr" #'kubectl--deployments-refresh
"o" #'kubectl--deployments-open
"RET" #'kubectl--deployments-open
"i" #'kubectl--deployments-inspect)
(general-def 'normal kubectl-statefulsets-mode-map
"c" #'kubectl-choose-context
"s" #'kubectl-choose-namespace
"gr" #'kubectl--statefulsets-refresh
"o" #'kubectl--statefulsets-open
"RET" #'kubectl--statefulsets-open
"i" #'kubectl--statefulsets-inspect)
:commands (kubectl-choose-context
kubectl-choose-namespace
kubectl-deployments
kubectl-statefulsets))
2021-04-05 14:46:20 +00:00
(when (executable-find "k9s")
(defun k9s ()
(interactive)
(let ((k9s-buf (vterm "*k9s*")))
(switch-to-buffer k9s-buf)
(vterm-send-string (executable-find "k9s"))
(vterm-send-return))))
2021-02-27 04:55:06 +00:00
(provide 'init-kubernetes)