("RET" "Display" kubed-transient-display)
("+" "Create" kubed-transient-create)
("*" "Apply" kubed-transient-apply)
- ("E" "Explain" kubed-explain)]
+ ("D" "Delete" kubed-transient-delete)]
;; Second column.
[("r" "Run" kubed-transient-run)
("a" "Attach" kubed-transient-attach)
[("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 (autoload 'kubed-transient-rollout "kubed-transient" nil t)
("S" "Secret" kubed-display-secret)
("N" "Namespace" kubed-display-namespace)
("i" "Ingress" kubed-display-ingress)
- ("RET" "Any" kubed-display-resource)
+ ("RET" "Any type" kubed-display-resource)
("!" "Command line" kubed-kubectl-command)]
["Options"
("-n" "Namespace" "--namespace="
(transient-setup 'kubed-transient-display nil nil
:scope '("get")))
+;;;###autoload (autoload 'kubed-transient-delete "kubed-transient" nil t)
+(transient-define-prefix kubed-transient-delete ()
+ "Delete Kubernetes resource."
+ ["Kubernetes Delete\n"
+ ["Kinds"
+ ("p" "Pod" kubed-delete-pods)
+ ("d" "Deployment" kubed-delete-deployments)
+ ("j" "Job" kubed-delete-jobs)
+ ("c" "CronJob" kubed-delete-cronjobs)
+ ("s" "Service" kubed-delete-services)]
+ ["More"
+ :pad-keys t
+ ("S" "Secret" kubed-delete-secrets)
+ ("N" "Namespace" kubed-delete-namespaces)
+ ("i" "Ingress" kubed-delete-ingresses)
+ ("D" "Any type" kubed-delete-resources)
+ ("!" "Command line" kubed-kubectl-command)]
+ ["Options"
+ ("-n" "Namespace" "--namespace="
+ :prompt "Namespace" :reader kubed-transient-read-namespace)
+ ("-C" "Context" "--context="
+ :prompt "Context" :reader kubed-transient-read-context)]]
+ (interactive)
+ (transient-setup 'kubed-transient-delete nil nil
+ :scope '("delete")))
+
;;;###autoload (autoload 'kubed-transient-create-cronjob "kubed-transient" nil t)
(transient-define-prefix kubed-transient-create-cronjob ()
"Create Kubernetes cronjob."
(add-hook 'context-menu-functions #'kubed-list-context-menu nil t))
(defun kubed-delete-resources (type resources context &optional namespace)
- "Delete Kubernetes RESOURCES of type TYPE."
+ "Delete Kubernetes RESOURCES of type TYPE in CONTEXT.
+
+For namespaced resource types, NAMESPACE is the namespace of RESOURCE.
+
+Interactively, use the current context and namespace by default, and
+prompt for TYPE and RESOURCES. With a prefix argument \
+\\[universal-argument],
+prompt for NAMESPACE. With a double prefix argument \
+\\[universal-argument] \\[universal-argument],
+prompt for CONTEXT as well."
(interactive
- (let* ((type (kubed-read-resource-type "Resource type to delete"))
- (context (kubed-current-context))
- (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-delete))
- (let ((cur (kubed-current-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur)
- cur))))))
- (list type (kubed-read-resource-name type "Delete" nil t nil namespace)
+ (let ((type nil) (context nil) (namespace nil))
+ (dolist (arg (kubed-transient-args 'kubed-transient-delete))
+ (cond
+ ((string-match "--namespace=\\(.+\\)" arg)
+ (setq namespace (match-string 1 arg)))
+ ((string-match "--context=\\(.+\\)" arg)
+ (setq context (match-string 1 arg)))))
+ (unless context
+ (setq context
+ (let ((cxt (kubed-local-context)))
+ (if (equal current-prefix-arg '(16))
+ (kubed-read-context "Context" cxt)
+ cxt))))
+ (unless type
+ (setq type (kubed-read-resource-type "Type of resource to delete"
+ nil context)))
+ (when (and (kubed-namespaced-p type context) (null namespace))
+ (setq namespace
+ (let ((cur (kubed-local-namespace context)))
+ (if current-prefix-arg
+ (kubed-read-namespace "Namespace" cur nil context)
+ cur))))
+ (list type (kubed-read-resource-name type "Delete" nil t
+ context namespace)
context namespace)))
(unless resources (user-error "You didn't specify %s to delete" type))
(message (format "Deleting Kubernetes %s `%s'..."
(defun ,dlt-name (,plrl-var &optional context
. ,(when namespaced '(namespace)))
- ,(format "Delete Kubernetes %S %s." plrl-var
- (upcase (symbol-name plrl-var)))
- (interactive ,(if namespaced
- `(let ((namespace (and current-prefix-arg
- (kubed-read-namespace
- "Namespace" (kubed-current-namespace)))))
- (list (,read-fun "Delete" nil t nil namespace) nil namespace))
- `(list (,read-fun "Delete" nil t))))
+ ,(if namespaced
+ (format "Delete Kubernetes %S %s in CONTEXT and NAMESPACE.
+
+Interactively, use the current context and namespace by default. With a
+prefix argument \\[universal-argument], prompt for NAMESPACE. With a
+double prefix argument \\[universal-argument] \\[universal-argument], \
+prompt for CONTEXT as well." plrl-var (upcase (symbol-name plrl-var)))
+ (format "Delete Kubernetes %S %s in context CONTEXT.
+
+Interactively, use the current context. With a prefix argument
+\\[universal-argument], prompt for CONTEXT." plrl-var (upcase (symbol-name plrl-var))))
+ (interactive
+ ,(if namespaced
+ `(let ((context nil) (namespace nil))
+ (dolist (arg (kubed-transient-args 'kubed-transient-delete))
+ (cond
+ ((string-match "--namespace=\\(.+\\)" arg)
+ (setq namespace (match-string 1 arg)))
+ ((string-match "--context=\\(.+\\)" arg)
+ (setq context (match-string 1 arg)))))
+ (unless context
+ (setq context
+ (let ((cxt (kubed-local-context)))
+ (if (equal current-prefix-arg '(16))
+ (kubed-read-context "Context" cxt)
+ cxt))))
+ (unless namespace
+ (setq namespace
+ (let ((cur (kubed-local-namespace context)))
+ (if current-prefix-arg
+ (kubed-read-namespace "Namespace" cur nil context)
+ cur))))
+ (list (,read-fun "Delete" nil t context namespace) context namespace))
+ `(let ((context nil))
+ (dolist (arg (kubed-transient-args 'kubed-transient-delete))
+ (cond
+ ((string-match "--context=\\(.+\\)" arg)
+ (setq context (match-string 1 arg)))))
+ (unless context
+ (setq context
+ (let ((cxt (kubed-local-context)))
+ (if current-prefix-arg
+ (kubed-read-context "Context" cxt)
+ cxt))))
+ (list (,read-fun "Delete" nil t context) context))))
(unless ,plrl-var
(user-error ,(format "You didn't specify %S to delete" plrl-var)))
- (kubed-delete-resources ,(symbol-name plrl-var) ,plrl-var context
- . ,(when namespaced '(namespace))))
+ (let ((context (or context (kubed-local-context))))
+ (kubed-delete-resources
+ ,(symbol-name plrl-var) ,plrl-var context
+ . ,(when namespaced '((or namespace (kubed-local-namespace context)))))))
,(if crt-spec `(defun ,crt-name . ,crt-spec)
`(defun ,crt-name (definition)