["Actions"
("c" "Create" kubed-transient-create)
("r" "Run" kubed-transient-run)
+ ("a" "Attach" kubed-transient-attach)
("!" "Command line" kubed-kubectl-command)])
+;;;###autoload
+(transient-define-prefix kubed-transient-attach ()
+ "Attach to running process in container in Kubernetes pod."
+ ["Switches"
+ ("-i" "Open stdin" "--stdin")
+ ("-t" "Allocate TTY" "--tty")]
+ ["Options"
+ ("-n" "Namespace" "--namespace="
+ :prompt "Namespace" :reader kubed-transient-read-namespace)]
+ ["Actions"
+ ("a" "Attach" kubed-attach)
+ ("!" "Command line" kubed-kubectl-command)]
+ (interactive)
+ (transient-setup 'kubed-transient-attach nil nil
+ :value '("--stdin")
+ :scope '("attach")))
+
;;;###autoload
(transient-define-prefix kubed-transient-run ()
"Run container image in a Kubernetes pod."
(format-prompt prompt default) nil nil nil nil
'kubed-container-images-history default))
+;;;###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."
+ (interactive
+ (let ((namespace nil) (stdin nil) (tty nil))
+ (dolist (arg (when (and (fboundp 'transient-args)
+ (fboundp 'kubed-transient-attach))
+ (transient-args 'kubed-transient-attach)))
+ (cond
+ ((string-match "--namespace=\\(.+\\)" arg)
+ (setq namespace (match-string 1 arg)))
+ ((equal "--stdin" arg) (setq stdin t))
+ ((equal "--tty" arg) (setq tty t))))
+ (if (and kubed-all-namespaces-mode (not namespace))
+ (let* ((p-s (kubed-read-namespaced-pod "Attach to pod"))
+ (p (car p-s))
+ (s (cadr p-s)))
+ (list p (kubed-read-container p "Container" t s) s stdin tty))
+ ;; 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)))
+ (list p c namespace stdin tty)))))
+ (pop-to-buffer
+ (apply #'make-comint "kubed-attach" kubed-kubectl-program nil
+ "attach" pod
+ (append
+ (when namespace (list "-n" namespace))
+ (when container (list "-c" container))
+ (when stdin '("-i"))
+ (when tty '("-t"))))))
+
(defvar kubed-kubectl-command-history nil
"Minibuffer history for `kubed-kubectl-command'.")
"A" #'kubed-all-namespaces-mode
"+" #'kubed-create
"R" #'kubed-run
+ "@" #'kubed-attach
"!" #'kubed-kubectl-command)
(provide 'kubed)