"Return non-nil if TYPE is a namespaced resource type in context CONTEXT."
(member type (kubed-api-resources context t)))
+(defun kubed--namespace (context &optional prompt-p)
+ "Return Kubernetes namespace for CONTEXT.
+
+Non-nil optional argument PROMPT-P says to prompt for a namespace."
+ (let ((ns (if (equal context (kubed-local-context))
+ (kubed-local-namespace)
+ (kubed-current-namespace context))))
+ (if prompt-p
+ (kubed-read-namespace "Namespace" ns nil context)
+ ns)))
+
;;;###autoload
(defun kubed-display-resource
(type resource context &optional namespace)
(unless type
(setq type (kubed-read-resource-type "Type of resource to display"
nil context)))
- (when (and (kubed-namespaced-p type context) (null namespace))
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (when (and (null namespace) (kubed-namespaced-p type context))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list type (kubed-read-resource-name type "Display" nil nil
context namespace)
context namespace)))
(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)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (when (and (null namespace) (kubed-namespaced-p type context))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list type (kubed-read-resource-name type "Delete" nil t
context namespace)
context namespace)))
(unless type
(setq type (kubed-read-resource-type "Type of resource to edit"
nil context)))
- (when (and (kubed-namespaced-p type context) (null namespace))
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (when (and (null namespace) (kubed-namespaced-p type context))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list type (kubed-read-resource-name type "Edit" nil nil
context namespace)
context namespace)))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (,read-fun "Display" nil nil context namespace) context namespace))
`(let ((context nil))
(dolist (arg (kubed-transient-args 'kubed-transient-display))
(let ((context (or context (kubed-local-context))))
(kubed-display-resource
,(symbol-name plrl-var) ,resource context
- . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
+ . ,(when namespaced '((or namespace (kubed--namespace context)))))))
(defun ,edt-name (,resource &optional context . ,(when namespaced '(namespace)))
,(if namespaced
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (,read-fun "Edit" nil nil context namespace) context namespace))
`(let ((context nil))
(dolist (arg (kubed-transient-args 'kubed-transient-edit))
(let ((context (or context (kubed-local-context))))
(kubed-edit-resource
,(symbol-name plrl-var) ,resource context
- . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
+ . ,(when namespaced '((or namespace (kubed--namespace context)))))))
(defun ,dlt-name (,plrl-var &optional context
. ,(when namespaced '(namespace)))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (,read-fun "Delete" nil t context namespace) context namespace))
`(let ((context nil))
(dolist (arg (kubed-transient-args 'kubed-transient-delete))
(let ((context (or context (kubed-local-context))))
(kubed-delete-resources
,(symbol-name plrl-var) ,plrl-var context
- . ,(when namespaced '((or namespace (kubed-local-namespace)))))))
+ . ,(when namespaced '((or namespace (kubed--namespace context)))))))
,(if crt-spec `(defun ,crt-name . ,crt-spec)
`(defun ,crt-name (definition &optional context)
(kubed-read-context "Context" context)
context)))
(list context
- . ,(when namespaced
- '((let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur)))))))
+ . ,(when namespaced '((kubed--namespace context current-prefix-arg))))))
(pop-to-buffer (,buff-fun context . ,(when namespaced '(namespace)))))
(defun ,expl-cmd ()
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list name
(kubed-read-cronjob
(format "Create job `%s' from cronjob" name) nil nil context namespace)
context namespace)))
- (let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace))))
+ (let* ((context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
(unless (zerop
(call-process
kubed-kubectl-program nil nil nil
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(unless image
(setq image (kubed-read-container-image "Image to run in job")))
(list name image context namespace command)))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (kubed-read-deployment "Watch deployment status" nil nil
context namespace)
context namespace)))
- (let ((buf (get-buffer-create "*kubed-deployment-status*"))
- (context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace))))
+ (let* ((buf (get-buffer-create "*kubed-deployment-status*"))
+ (context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
(with-current-buffer buf (erase-buffer))
(make-process
:name "*kubed-watch-deployment-status*"
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (kubed-read-deployment "Restart deployment" nil nil
context namespace)
context namespace)))
- (let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace))))
+ (let* ((context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
(unless (zerop
(apply #'call-process
kubed-kubectl-program nil nil nil
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list name images context namespace replicas port command)))
- (let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace))))
+ (let* ((context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
(unless (zerop
(apply #'call-process
kubed-kubectl-program nil nil nil
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(unless image
(setq image (kubed-read-container-image "Image to run")))
(unless schedule
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(unless rules (setq rules (kubed-read-ingress-rules)))
(list name rules context namespace class default-backend annotations)))
(unless (zerop
(car (process-lines kubed-kubectl-program "config" "current-context")))
(defun kubed-default-context-and-namespace ()
+ "Return default context and namespace as a cons cell (CONTEXT . NAMESPACE)."
(or kubed-default-context-and-namespace
(setq kubed-default-context-and-namespace
(let ((context (kubed-current-context)))
(kubed-current-namespace context))))))
(defun kubed-default-context ()
+ "Return default `kubectl' context."
(car (kubed-default-context-and-namespace)))
(defun kubed-default-namespace ()
+ "Return default Kubernetes namespace in the default context."
(cdr (kubed-default-context-and-namespace)))
(defun kubed-local-context ()
(context (if current-prefix-arg
(kubed-read-context "Context" context)
context)))
- (list (kubed-read-namespace "Set namespace" (kubed-local-namespace)
+ (list (kubed-read-namespace "Set namespace" (kubed--namespace context)
nil context)
context)))
(unless (zerop
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(setq pod (read-string "Run image in pod with name: "))
(unless image
(setq image (read-string "Image to run: " nil 'kubed-container-image-history)))
(context (if (equal current-prefix-arg '(16))
(kubed-read-context "Context" context)
context))
- (n (kubed-local-namespace))
- (n (if current-prefix-arg
- (kubed-read-namespace "Namespace" n nil context)
- n))
+ (n (kubed--namespace context current-prefix-arg))
(p (kubed-read-pod "Show logs for pod" nil nil context n))
(c (kubed-read-container p "Container" nil context n)))
(list p c context n)))
(let* ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace)))
+ (namespace (or namespace (kubed--namespace context)))
(buf (generate-new-buffer
(format "*kubed-logs %s[%s] in %s[%s]*"
pod container namespace context))))
(c (if (equal current-prefix-arg '(16))
(kubed-read-context "Context" c)
c))
- (n (kubed-local-namespace))
+ (n (kubed--namespace c current-prefix-arg))
(n (if current-prefix-arg
(kubed-read-namespace "Namespace" n nil c)
n))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(let* ((p (kubed-read-pod "Exec on pod" nil nil context namespace))
(c (kubed-read-container p "Container" t context namespace)))
(list p c context namespace stdin tty))))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(unless command
(setq args (split-string-and-unquote
(read-string "Execute command: "))
(kubed-read-context "Context" cxt)
cxt))))
(unless namespace
- (setq namespace
- (let ((cur (kubed-local-namespace)))
- (if current-prefix-arg
- (kubed-read-namespace "Namespace" cur nil context)
- cur))))
+ (setq namespace (kubed--namespace context current-prefix-arg)))
(list (kubed-read-resource-type "Resource type to patch" nil context)
(kubed-read-resource-name type "Resource to patch" nil nil context namespace)
(kubed-read-patch) context namespace strategy)))
(defun kubed-resource-names (type &optional context namespace)
"Return list of Kuberenetes resources of type TYPE in NAMESPACE via CONTEXT."
- (let ((context (or context (kubed-local-context)))
- (namespace (or namespace (kubed-local-namespace))))
+ (let* ((context (or context (kubed-local-context)))
+ (namespace (or namespace (kubed--namespace context))))
(unless (kubed--alist type context namespace)
(let ((proc (kubed-update type context namespace)))
(while (process-live-p proc)