"Perform Kubernetes operation."
["Kubernetes"
;; First column.
- [("+" "Create" kubed-transient-create)
- ("*" "Apply" kubed-transient-apply)
- ("r" "Run" kubed-transient-run)
- ("a" "Attach" kubed-transient-attach)
- ("d" "Diff" kubed-transient-diff)]
+ [ :pad-keys t
+ ("RET" "Display" kubed-transient-display)
+ ("+" "Create" kubed-transient-create)
+ ("*" "Apply" kubed-transient-apply)
+ ("E" "Explain" kubed-explain)]
;; Second column.
- [("X" "Exec" kubed-transient-exec)
+ [("r" "Run" kubed-transient-run)
+ ("a" "Attach" kubed-transient-attach)
+ ("X" "Exec" kubed-transient-exec)
+ ("R" "Rollout" kubed-transient-rollout)]
+ ;; Third column.
+ [("d" "Diff" kubed-transient-diff)
("P" "Patch" kubed-transient-patch)
("R" "Rollout" kubed-transient-rollout)
- ("E" "Explain" kubed-explain)
("!" "Command line" kubed-kubectl-command)]])
;;;###autoload
(transient-setup 'kubed-transient-create nil nil
:scope '("create")))
+;;;###autoload
+(transient-define-prefix kubed-transient-display ()
+ "Display Kubernetes resource."
+ ["Kubernetes Display\n"
+ ["Kinds"
+ ("p" "Pod" kubed-display-pod)
+ ("d" "Deployment" kubed-display-deployment)
+ ("j" "Job" kubed-display-job)
+ ("c" "CronJob" kubed-display-cronjob)
+ ("s" "Service" kubed-display-service)]
+ ["More"
+ :pad-keys t
+ ("S" "Secret" kubed-display-secret)
+ ("N" "Namespace" kubed-display-namespace)
+ ("i" "Ingress" kubed-display-ingress)
+ ("RET" "Any" kubed-display-resource)
+ ("!" "Command line" kubed-kubectl-command)]
+ ["Options"
+ ("-n" "Namespace" "--namespace="
+ :prompt "Namespace" :reader kubed-transient-read-namespace)]]
+ (interactive)
+ (transient-setup 'kubed-transient-display nil nil
+ :scope '("get")))
+
;;;###autoload
(transient-define-prefix kubed-transient-create-cronjob ()
"Create Kubernetes cronjob."
(kubed-display-resource-mode)
(current-buffer))))
+(defun kubed-display-resource-short-description
+ (type resource context namespace)
+ (concat type "/" resource
+ (when namespace (concat "@" namespace))
+ (when context (concat "[" context "]"))))
+
+(defun kubed-namespaced-p (type)
+ "Return non-nil if TYPE is a namespaced Kubernetes resource type."
+ (member type (kubed-api-resources t)))
+
+;;;###autoload
+(defun kubed-display-resource
+ (type resource context namespace)
+ "Display Kubernetes RESOURCE of type TYPE in BUFFER."
+ (interactive
+ (let* ((type (kubed-read-resource-type "Resource type to display"))
+ (namespace
+ (when (kubed-namespaced-p type)
+ (or (seq-some
+ (lambda (arg)
+ (when (string-match "--namespace=\\(.+\\)" arg)
+ (match-string 1 arg)))
+ (kubed-transient-args 'kubed-transient-display))
+ (let ((cur (kubed-current-namespace)))
+ (if current-prefix-arg
+ (kubed-read-namespace "Namespace" cur)
+ cur))))))
+ (list type (kubed-read-resource-name type "Display" nil namespace)
+ (kubed-current-context) namespace)))
+ (display-buffer
+ (kubed-display-resource-in-buffer
+ (concat "*Kubed "
+ (kubed-display-resource-short-description
+ type resource context namespace)
+ "*")
+ type resource context namespace)))
+
(declare-function bookmark-prop-get "bookmark")
(declare-function bookmark-get-front-context-string "bookmark")
(declare-function bookmark-get-rear-context-string "bookmark")
(bookmark-prop-get bookmark 'resource)
(set-buffer
(kubed-display-resource-in-buffer
- (concat "*Kubed " type "/" name
- (when namespace (concat "@" namespace))
- (when context (concat "[" context "]"))
+ (concat "*Kubed "
+ (kubed-display-resource-short-description
+ type name context namespace)
"*")
type name context namespace))
(when-let ((str (bookmark-get-front-context-string bookmark))
(require 'bookmark)
(seq-let (type name context namespace) kubed-display-resource-info
(cons
- (concat type "/" name
- (when namespace (concat "@" namespace))
- (when context (concat "[" context "]")))
+ (kubed-display-resource-short-description type name context namespace)
(append
(list
(cons 'handler #'kubed-display-resource-handle-bookmark)
(defun ,dsp-name (,resource . ,(when namespaced '(&optional k8sns)))
,(format "Display Kubernetes %S %s."
resource (upcase (symbol-name resource)))
- (interactive ,(if namespaced
- `(if kubed-all-namespaces-mode
- (,read-nms "Display")
- (list (,read-fun "Display")))
- `(list (,read-fun "Display"))))
+ (interactive
+ ,(if namespaced
+ `(if kubed-all-namespaces-mode
+ (,read-nms "Display")
+ (list (,read-fun "Display" nil nil
+ ;; Consult transient for --namespace.
+ (seq-some
+ (lambda (arg)
+ (when (string-match "--namespace=\\(.+\\)" arg)
+ (match-string 1 arg)))
+ (kubed-transient-args 'kubed-transient-display)))))
+ `(list (,read-fun "Display"))))
(display-buffer (,desc-fun ,resource . ,(when namespaced '(k8sns)))))
(add-hook 'kubed-update-hook #',updt-cmd)
"+" #',crt-name
"e" #',edt-name
"d" #',dlt-name
- "g" #',dsp-name
+ "RET" #',dsp-name
"u" #',updt-cmd
"E" #',expl-cmd
,@(mapcan
(defvar kubed-resource-field-history nil
"Minibuffer history for `kubed-read-resource-field'.")
-(defun kubed-api-resources ()
- "Return list of resource types in the current Kubernetes context."
+(defun kubed-api-resources (&optional only-namespaced)
+ "Return list of resource types in the current Kubernetes context.
+
+Non-nil optional argument ONLY-NAMESPACED says to return only namespaced
+resource types."
(mapcar
(lambda (line)
(car (split-string line)))
- (process-lines
- kubed-kubectl-program
- "api-resources" "--no-headers")))
+ (apply #'process-lines
+ kubed-kubectl-program
+ "api-resources" "--no-headers"
+ (when only-namespaced
+ '("--namespaced=true")))))
(defun kubed-resource-names (type &optional namespace)
"Return list of Kuberenetes resource names of type TYPE in NAMESPACE."
"=" #'kubed-diff
"E" #'kubed-explain
"P" #'kubed-patch
+ "RET" #'kubed-display-resource
"!" #'kubed-kubectl-command)
(defvar-keymap kubed-menu-map
"<use-context>" '("Set Current Context" . kubed-use-context)
"<run>" '("Run Image" . kubed-run)
"<apply>" '("Apply Config" . kubed-apply)
- "<create>" '("Create Resource" . kubed-create))
+ "<create>" '("Create Resource" . kubed-create)
+ "<display>" '("Display Resource" . kubed-display-resource))
;;;###autoload
(define-minor-mode kubed-menu-bar-mode