From cf970c3b518b0768d849f6fcc1a61c4fb8792e9f Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 24 Jul 2024 08:36:03 +0200 Subject: [PATCH] kubed.el: Add global prefix keymap --- lisp/net/kubed.el | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/lisp/net/kubed.el b/lisp/net/kubed.el index 080e37e0cc6..6b1bdde6773 100644 --- a/lisp/net/kubed.el +++ b/lisp/net/kubed.el @@ -111,6 +111,9 @@ interacting with Kubernetes RESOURCEs: - `kubed-update-RESROURCEs': update and repopulate RESOURCEs list. - `kubed-create-RESROURCE': create a RESOURCE from a YAML or a JSON file. +This macro also defines a prefix keymap, `kubed-RESOURCE-prefix-map', +with bindings for the above commands. + PROPERTIES is a list of elements (PROPERTY JSON-PATH WIDTH SORT . ATTRS) that specify properties of RESOURCEs. PROPERTY is the name of the property, as a symbol; JSON-PATH is a JSONPath expression that evaluates @@ -154,7 +157,15 @@ namespaceless resource type, put `:namespaced nil' before COMMANDS: (kubed-define-resource global-thingy (PROP1 PROP2 ...) :namespaced nil CMD1 CMD2 - ...)" + ...) + +Other keyword arguments that go between PROPERTIES and COMMANDS are: + +- `:create (ARGLIST DOCSTRING INTERACTIVE BODY...)': specialize the + resource creation command, `kubed-create-RESROURCE'. ARGLIST, + DOCSTRING, INTERACTIVE and BODY have the same meaning as in `defun'. +- `:prefix (KEY DEFINITION...)': additional keybinding for the prefix + keymap `kubed-RESOURCE-prefix-map'." (declare (indent 2)) (let ((hist-var (intern (format "kubed-%S-history" resource))) (list-var (intern (format "kubed-%Ss" resource))) @@ -189,6 +200,7 @@ namespaceless resource type, put `:namespaced nil' before COMMANDS: (crt-name (intern (format "kubed-create-%S" resource))) (map-name (intern (format "kubed-%S-prefix-map" resource))) (crt-spec nil) + (prf-keys nil) (namespaced t) (keyword nil)) @@ -198,6 +210,7 @@ namespaceless resource type, put `:namespaced nil' before COMMANDS: (cond ((eq keyword :namespaced) (setq namespaced (pop commands))) ((eq keyword :create) (setq crt-spec (pop commands))) + ((eq keyword :prefix) (setq prf-keys (pop commands))) ;; FIXME: Add error for unknown keywords. (t (pop commands)))) @@ -796,7 +809,9 @@ Optional argument DEFAULT is the minibuffer default argument." resource) "c" #',crt-name "e" #',edt-name "d" #',dlt-name - "g" #',dsp-name)))) + "g" #',dsp-name + "u" #',updt-cmd + ,@prf-keys)))) (defvar tramp-kubernetes-namespace) @@ -808,6 +823,8 @@ Optional argument DEFAULT is the minibuffer default argument." resource) ;;;###autoload (autoload 'kubed-pod-prefix-map "kubed" nil t 'keymap) (kubed-define-resource pod ((phase ".status.phase" 10) (starttime ".status.startTime" 20)) + :prefix ("L" #'kubed-logs + "F" #'kubed-forward-port-to-pod) (dired "C-d" "Start Dired in home directory of first container of" ;; FIXME: This doesn't really make sense for other namespaces, ;; we create the Dired buffer using the correct namespace, but @@ -840,6 +857,7 @@ Optional argument DEFAULT is the minibuffer default argument." resource) ((phase ".status.phase" 10) (creationtimestamp ".metadata.creationTimestamp" 20)) :namespaced nil + :prefix ("S" #'kubed-set-namespace) :create ((name) "Create Kubernetes namespace with name NAME." (interactive (list (read-string "Create namespace with name: "))) @@ -1087,7 +1105,14 @@ completion candidates." (defun kubed-create (definition &optional kind) "Create Kubernetes resource of kind KIND with definition DEFINITION." (interactive - (list (kubed-read-resource-definition-file-name))) + (list (or (and (fboundp 'transient-args) + (fboundp 'kubed-transient-create-deployment) + (seq-some + (lambda (arg) + (when (string-match "--filename=\\(.+\\)" arg) + (match-string 1 arg))) + (transient-args 'kubed-transient-create))) + (kubed-read-resource-definition-file-name)))) (let ((kind (or kind "resource"))) (message "Creating Kubernetes %s with definition `%s'..." kind definition) (message "Creating Kubernetes %s with definition `%s'... Done. New %s name is `%s'." @@ -1241,5 +1266,19 @@ Optional argument DEFAULT is the minibuffer default argument." (format-prompt prompt default) nil nil nil nil 'kubed-container-images-history default)) +;;;###autoload (autoload 'kubed-prefix-map "kubed" nil t 'keymap) +(defvar-keymap kubed-prefix-map + :doc "Prefix keymap for Kubed commands." + :prefix 'kubed-prefix-map + "p" 'kubed-pod-prefix-map + "N" 'kubed-namespace-prefix-map + "s" 'kubed-service-prefix-map + "S" 'kubed-secret-prefix-map + "j" 'kubed-job-prefix-map + "d" 'kubed-deployment-prefix-map + "C" #'kubed-use-context + "A" #'kubed-all-namespaces-mode + "+" #'kubed-create) + (provide 'kubed) ;;; kubed.el ends here -- 2.39.2