(kubed-define-resource pod
((phase ".status.phase" 10) (starttime ".status.startTime" 20))
:prefix ("L" #'kubed-logs
+ "A" #'kubed-attach
"F" #'kubed-forward-port-to-pod)
(dired "C-d" "Start Dired in home directory of first container of"
(let ((ns (when k8sns (concat "%" k8sns))))
(let* ((ns (when k8sns (concat "%" k8sns)))
(default-directory (concat "/kubernetes:" pod ns ":")))
(shell (format "*kubed-pod-%s-shell*" pod))))
+ (attach "a" "Attach to remote process running on"
+ (kubed-attach pod (kubed-read-container pod "Container" t k8sns)
+ k8sns t t))
(logs "l" "Show logs for a container of"
(kubed-logs pod (kubed-read-container pod "Container" t k8sns)))
(forward-port "F" "Forward local network port to remote port of"
(port nil)
(command nil)
(namespace nil))
- (dolist (arg (when (and (fboundp 'transient-args)
- (fboundp 'kubed-transient-create-deployment))
- (transient-args 'kubed-transient-create-deployment)))
+ (dolist (arg (kubed-transient-args 'kubed-transient-create-deployment))
(cond
((string-match "--replicas=\\(.+\\)" arg)
(setq replicas (string-to-number (match-string 1 arg))))
(defun kubed-create (definition &optional kind)
"Create Kubernetes resource of kind KIND with definition DEFINITION."
(interactive
- (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)))
+ (list (or (seq-some
+ (lambda (arg)
+ (when (string-match "--filename=\\(.+\\)" arg)
+ (match-string 1 arg)))
+ (kubed-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)
(let ((pod (read-string "Run image in pod with name: "))
(image nil) (port nil) (namespace nil) (attach nil) (stdin nil)
(tty nil) (rm nil) (envs nil) (command nil) (args nil))
- (dolist (arg (when (and (fboundp 'transient-args)
- (fboundp 'kubed-transient-run))
- (transient-args 'kubed-transient-run)))
+ (dolist (arg (kubed-transient-args 'kubed-transient-run))
(cond
((string-match "--image=\\(.+\\)" arg)
(setq image (match-string 1 arg)))
(format-prompt prompt default) nil nil nil nil
'kubed-container-images-history default))
+(defvar transient-current-command)
+
+(defun kubed-transient-args (&optional prefix)
+ "Return current arguments from transient PREFIX.
+
+If PREFIX nil, it defaults to the value of `transient-current-command'."
+ (when-let ((prefix (or prefix (bound-and-true-p transient-current-command))))
+ (and (featurep 'kubed-transient)
+ (fboundp 'transient-args)
+ (transient-args prefix))))
+
;;;###autoload
(defun kubed-attach (pod &optional container namespace stdin tty)
"Attach to running process in CONTAINER in Kubernetes POD.
Optional argument NAMESPACE is the namespace in which to look for POD.
pod/foobar created
Non-nil STDIN says to connect local standard input to remote process.
-Non-nil TTY says to use a TTY for standard input."
+Non-nil TTY says to use a TTY for standard input.
+
+Interactively, prompt for POD; if there are multiple pod containers,
+prompt for CONTAINER as well; STDIN is t unless you call this command
+with \\[universal-argument] \\[universal-argument]; and TTY is t unless\
+ you call this command with \\[universal-argument]."
(interactive
- (let ((namespace nil) (stdin nil) (tty nil))
- (dolist (arg (when (and (fboundp 'transient-args)
- (fboundp 'kubed-transient-attach))
- (transient-args 'kubed-transient-attach)))
+ (let ((namespace nil) (stdin t) (tty t))
+ (when (<= 4 (prefix-numeric-value current-prefix-arg)) (setq tty nil))
+ (when (<= 16 (prefix-numeric-value current-prefix-arg)) (setq stdin nil))
+ (dolist (arg (kubed-transient-args 'kubed-transient-attach))
(cond
((string-match "--namespace=\\(.+\\)" arg)
(setq namespace (match-string 1 arg)))
;; FIXME: When namespace is set from transient prefix, read pod
;; name in that namespace instead.
(let* ((p (kubed-read-pod "Attach to pod"))
- (c (kubed-read-container p "Container" t)))
+ (c (kubed-read-container p "Container" t namespace)))
(list p c namespace stdin tty)))))
(pop-to-buffer
(apply #'make-comint "kubed-attach" kubed-kubectl-program nil
(defvar kubed-kubectl-command-history nil
"Minibuffer history for `kubed-kubectl-command'.")
-(defvar transient-current-command)
-
;;;###autoload
(defun kubed-kubectl-command (command)
"Execute `kubectl' COMMAND.
"Command: "
(concat
kubed-kubectl-program " "
- (when-let
- ((args
- (and (fboundp 'transient-args)
- (fboundp 'transient-scope)
- transient-current-command
- (string-join
- (append (transient-scope)
- (transient-args transient-current-command))
- " "))))
- (concat args " ")))
+ (when-let ((args (kubed-transient-args)))
+ (concat (string-join
+ (append (and (fboundp 'transient-scope) (transient-scope))
+ args)
+ " ")
+ " ")))
'kubed-kubectl-command-history)))
(shell-command command))
"+" #'kubed-create
"R" #'kubed-run
"D" #'kubed-diff
- "@" #'kubed-attach
"!" #'kubed-kubectl-command)
(provide 'kubed)