Add kubectl.el

This commit is contained in:
Jeremy Dormitzer 2021-02-26 23:55:06 -05:00
parent dbf65caabe
commit 2397203e80
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,53 @@
;; -*- 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))
(provide 'init-kubernetes)

View File

@ -86,6 +86,7 @@
(require 'init-prodigy)
(require 'init-direnv)
(require 'init-email)
(require 'init-kubernetes)
;; Load the custom file
(when (file-exists-p custom-file)