Upgrade package

This commit is contained in:
Marcus Kammer 2020-02-20 17:25:32 +01:00
parent 869a965942
commit 05194b1de2
405 changed files with 124 additions and 8302 deletions

View file

@ -1517,7 +1517,7 @@
("Phillip Lord" . "phillip.lord@russet.org.uk"))
(:url . "http://elpa.gnu.org/packages/persist.html"))])
(phps-mode .
[(0 3 34)
[(0 3 36)
((emacs
(26)))
"Major mode for PHP with Semantic integration" tar

View file

@ -1,171 +0,0 @@
;;; ein-k8s.el --- hooks to chrisbarrett's kubernetes*.el -*- lexical-binding: t; -*-
;; Copyright (C) 2019 The Authors
;; Authors: dickmao <github id: dickmao>
;; This file is NOT part of GNU Emacs.
;; ein-k8s.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; ein-k8s.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with ein-k8s.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'kubernetes)
(defcustom ein:k8s-name-deployment nil
"Regexp by which we recognize jupyter services."
:type 'string
:group 'ein)
(defcustom ein:k8s-name-service "jupyter-service"
"Regexp by which we recognize jupyter services."
:type 'string
:group 'ein)
(defun ein:k8s-select-context (&optional query-p)
(interactive "p")
(when (or query-p
(null (kubernetes-state-config (kubernetes-state))))
(kubernetes-contexts-refresh-now)
(if-let ((contexts (ein:k8s-get-contexts)))
(let ((desired-context
(ein:completing-read "Select context: " contexts nil t)))
(message "Rereading state...")
(kubernetes-state-clear)
(let ((response
(kubernetes-kubectl-await
(apply-partially #'kubernetes-kubectl
kubernetes-props
(kubernetes-state)
(split-string (format "config use-context %s"
desired-context)))
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "Switched to context \""
(group (+? nonl)) "\"." (* space) eol)
(buffer-string))
(match-string 1 (buffer-string)))))))
(if (string= response desired-context)
(progn
(kubernetes-state-update-config (kubernetes-kubectl-await-on-async
kubernetes-props
(kubernetes-state)
#'kubernetes-kubectl-config-view))
(let ((current-name (alist-get
'name
(kubernetes-state-current-context
(kubernetes-state)))))
(unless (string= current-name desired-context)
(error "ein:k8s-select-context': could not update state for %s"
desired-context))
(if (kubernetes-nodes-refresh-now)
(progn
(mapc (lambda (resource)
(when-let ((refresh-f
(intern-soft (format "kubernetes-%s-refresh-now" resource))))
(when (fboundp refresh-f)
(funcall refresh-f))))
(cl-remove-if (apply-partially #'eq 'nodes)
(mapcar #'car kubernetes-overview-views-alist)))
(message ""))
(error "ein:k8s-select-context: %s is down" current-name))))
(error "ein:k8s-select-context: use-context returned %s, expected %s"
response desired-context))))
(error "ein:k8s-select-context: No contexts found"))))
(defun ein:k8s-get-contexts ()
(let ((response (kubernetes-kubectl-await-on-async kubernetes-props
(kubernetes-state)
#'kubernetes-kubectl-config-view)))
(-let* [((&alist 'contexts contexts 'current-context current) response)
(names (--map (alist-get 'name it) (append contexts nil)))]
(when (member current names)
(setq names (cons current (-remove-item current names))))
names)))
(defun ein:k8s-get-deployment ()
(-let* [(deployments (kubernetes-state-deployments (kubernetes-state)))
((&alist 'items items) deployments)]
(seq-some (lambda (it)
(-let [(&alist 'metadata (&alist 'name)) it]
(and (string= name ein:k8s-name-deployment) it)))
items)))
(defun ein:k8s-get-pod ()
(when-let ((deployment (ein:k8s-get-deployment)))
(cl-first (kubernetes-overview--pods-for-deployment (kubernetes-state)
deployment))))
(defun ein:k8s-get-service ()
(-let* [(services (kubernetes-state-services (kubernetes-state)))
((&alist 'items items) services)]
(seq-some (lambda (it)
(-let [(&alist 'metadata (&alist 'name)) it]
(and (string= name ein:k8s-name-service) it)))
items)))
(defun ein:k8s-get-node ()
(-when-let* ((pod (ein:k8s-get-pod))
((&alist 'spec (&alist 'nodeName)) pod)
(node (kubernetes-state-lookup-node nodeName (kubernetes-state)))
((&alist 'metadata (&alist 'name)) node))
node))
(defsubst ein:k8s-ensure ()
(and ein:k8s-name-deployment (executable-find kubernetes-kubectl-executable)
(condition-case err
(progn
(ein:k8s-select-context)
(kubernetes-state-current-context (kubernetes-state)))
(error (ein:log 'info "ein:k8s-ensure: %s" (error-message-string err))
nil))))
(defsubst ein:k8s-in-cluster (addr)
"Is ein client inside the k8s cluster?"
(if-let ((ip-command (executable-find "ip")))
(with-temp-buffer
(apply #'call-process ip-command nil t nil
(split-string (format "n ls %s" addr)))
(goto-char (point-min))
(search-forward addr nil t))
;; hack if ip command not found
(string= "minikube"
(alist-get 'name (kubernetes-state-current-context
(kubernetes-state))))))
(defun ein:k8s-service-url-or-port ()
(ein:k8s-ensure)
(-when-let* ((service (ein:k8s-get-service))
((&alist 'spec (&alist 'ports [(&alist 'nodePort)])) service)
(node (ein:k8s-get-node))
((&alist 'status (&alist 'addresses)) node)
(host-ip
(seq-some (lambda (address)
(when (string= (alist-get 'type address) "InternalIP")
(alist-get 'address address)))
addresses)))
(if (ein:k8s-in-cluster host-ip)
(ein:url (concat "http://" host-ip ":" (number-to-string nodePort)))
(when-let ((ips (kubernetes-kubectl-await-command ingress
(lambda (item)
(-let* (((&alist 'status
(&alist 'loadBalancer
(&alist 'ingress
[(&alist 'ip)])))
item))
ip)))))
(ein:url (concat "http://" (car ips)))))))
(provide 'ein-k8s)

Binary file not shown.

View file

@ -150,13 +150,6 @@ Log on to a jupyterhub server using PAM authentication. Requires jupyterhub vers
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ein-jupyterhub" '("ein:" "*ein:jupyterhub-connections*")))
;;;***
;;;### (autoloads nil "ein-k8s" "ein-k8s.el" (0 0 0 0))
;;; Generated autoloads from ein-k8s.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ein-k8s" '("ein:k8s-")))
;;;***
;;;### (autoloads nil "ein-kernel" "ein-kernel.el" (0 0 0 0))

View file

@ -42,11 +42,11 @@
(require 'ein-kernel)
(require 'ein-output-area)
(declare-function mm-encode-buffer "mm-encode")
(declare-function mm-possibly-verify-or-decrypt "mm-decode")
(declare-function mm-dissect-singlepart "mm-decode")
(declare-function mm-display-external "mm-decode")
(declare-function mm-handle-media-type "mm-decode")
(autoload 'mm-encode-buffer "mm-encode")
(autoload 'mm-possibly-verify-or-decrypt "mm-decode")
(autoload 'mm-dissect-singlepart "mm-decode")
(autoload 'mm-display-external "mm-decode")
(autoload 'mm-handle-media-type "mm-decode")
(defun ein:cell--ewoc-delete (ewoc &rest nodes)
"Delete NODES from EWOC."

View file

@ -86,12 +86,8 @@
(get-buffer-create (format "*ipdb: %s*" (ein:pdb-session-id session))))
(set (make-local-variable 'ein:ipdb-buffer-active-kernel) (ein:pdb-session-id session))
(set (make-local-variable 'ein:ipdb-buffer-prompt) prompt)
(put 'ein:ipdb-buffer-active-kernel 'permanent-local t)
(put 'ein:ipdb-buffer-prompt 'permanent-local t)
(add-hook 'kill-buffer-hook 'ein:ipdb-on-stop)
(ein:ipdb-mode)
(pop-to-buffer (ein:$ipdb-session-buffer session))))
(defun ein:ipdb-on-stop ()

View file

@ -26,7 +26,6 @@
(require 'ein-core)
(require 'ein-notebooklist)
(require 'ein-dev)
(require 'ein-k8s)
(defcustom ein:jupyter-use-containers nil
"Take EIN in a different direcsh."
@ -122,17 +121,7 @@ with the call to the jupyter notebook."
(defun ein:jupyter-process-lines (url-or-port command &rest args)
"If URL-OR-PORT registered as a k8s url, preface COMMAND ARGS with `kubectl exec'."
(condition-case err
(cond ((-when-let* ((url-or-port url-or-port)
(parsed-url (url-generic-parse-url url-or-port))
(not-local (not (string= (url-host parsed-url)
ein:url-localhost))))
(string= url-or-port (ein:k8s-service-url-or-port)))
(let ((pod-name (kubernetes-state-resource-name (ein:k8s-get-pod))))
(apply #'process-lines kubernetes-kubectl-executable
(nconc
(split-string (format "exec %s -- %s" pod-name command))
args))))
(t (apply #'process-lines command args)))
(apply #'process-lines command args)
(error (ein:log 'info "ein:jupyter-process-lines: %s" (error-message-string err))
nil)))
@ -238,20 +227,18 @@ our singleton jupyter server process here."
;;;###autoload
(defun ein:jupyter-crib-running-servers ()
"Shell out to jupyter for running servers."
(nconc
(cl-loop for line in
(apply #'ein:jupyter-process-lines nil
ein:jupyter-server-command
(split-string
(format "%s%s %s"
(aif ein:jupyter-server-use-subcommand
(concat it " ") "")
"list" "--json")))
collecting (destructuring-bind
(&key url &allow-other-keys)
(ein:json-read-from-string line)
(ein:url url)))
(aif (ein:k8s-service-url-or-port) (list it))))
(cl-loop for line in
(apply #'ein:jupyter-process-lines nil
ein:jupyter-server-command
(split-string
(format "%s%s %s"
(aif ein:jupyter-server-use-subcommand
(concat it " ") "")
"list" "--json")))
collecting (destructuring-bind
(&key url &allow-other-keys)
(ein:json-read-from-string line)
(ein:url url))))
;;;###autoload
(defun ein:jupyter-server-start (server-command

View file

@ -59,7 +59,7 @@
(require 'ein-notebooklist)
(require 'poly-ein)
(declare-function ob-ein-anonymous-p "ob-ein")
(autoload 'ob-ein-anonymous-p "ob-ein")
(make-obsolete-variable 'ein:use-smartrep nil "0.17.0")
@ -87,28 +87,6 @@ notebook. For global setting and more information, see
(const :tag "Use global setting" nil))
:group 'ein)
(defcustom ein:helm-kernel-history-search-key nil
"Bind `helm-ein-kernel-history' to this key in notebook mode.
Example::
(setq ein:helm-kernel-history-search-key \"\\M-r\")
This key will be installed in the `ein:notebook-mode-map'."
:type 'boolean
:group 'ein)
(defcustom ein:anything-kernel-history-search-key nil
"Bind `anything-ein-kernel-history' to this key in notebook mode.
Example::
(setq ein:anything-kernel-history-search-key \"\\M-r\")
This key will be installed in the `ein:notebook-mode-map'."
:type 'boolean
:group 'ein)
(defcustom ein:notebook-set-buffer-file-name nil
"[DEPRECATED] Set `buffer-file-name' of notebook buffer. Currently does nothing."
:type 'boolean
@ -169,28 +147,6 @@ And I don't know if I can on account of the dont-save-cells nonsense."
;;; Notebook utility functions
(defun ein:notebook-update-url-or-port (new-url-or-port notebook)
"Change the url and port the notebook is saved to. Calling
this will propagate the change to the kernel, trying to restart
the kernel in the process. Use case for this command is when
the jupyter server dies and restarted on a different port.
If you have enabled token or password security on server running
at the new url/port, then please be aware that this new url-port
combo must match exactly these url/port you used format
`ein:notebooklist-login'."
(interactive (list
(ein:notebooklist-ask-url-or-port)
(ein:notebook--get-nb-or-error)))
(message "Updating server info and restarting kernel for notebooklist %s"
(ein:$notebook-notebook-name notebook))
(setf (ein:$notebook-url-or-port notebook) new-url-or-port)
(with-current-buffer (ein:notebook-buffer notebook)
(ein:kernel-retrieve-session (ein:$notebook-kernel notebook))
(rename-buffer (format ein:notebook-buffer-name-template
(ein:$notebook-url-or-port notebook)
(ein:$notebook-notebook-name notebook)))))
(defun ein:notebook-buffer (notebook)
"Return first buffer in NOTEBOOK's worksheets."
(aif notebook
@ -1358,17 +1314,7 @@ watch the fireworks!"
;; BODY contains code to execute each time the mode is enabled or disabled.
;; It is executed after toggling the mode, and before running MODE-hook.
(when ein:notebook-mode
(aif ein:helm-kernel-history-search-key
(ein:notebook--define-key ein:notebook-mode-map it helm-ein-kernel-history))
(aif ein:anything-kernel-history-search-key
(ein:notebook--define-key ein:notebook-mode-map it anything-ein-kernel-history))
(setq indent-tabs-mode nil) ;; Being T causes problems with Python code.
))
;; To avoid MuMaMo to discard `ein:notebook-mode', make it
;; permanent local.
(put 'ein:notebook-mode 'permanent-local t)
)
(defun ein:notebook-fetch-data (notebook callback &optional cbargs)
"Fetch data in body tag of NOTEBOOK html page.

View file

@ -78,29 +78,12 @@
:type '(choice (const :tag "Name" :name)
(const :tag "Last modified" :last_modified))
:group 'ein)
(make-variable-buffer-local 'ein:notebooklist-sort-field)
(put 'ein:notebooklist-sort-field 'permanent-local t)
(defcustom ein:notebooklist-sort-order :ascending
"The notebook list sort order."
:type '(choice (const :tag "Ascending" :ascending)
(const :tag "Descending" :descending))
:group 'ein)
(make-variable-buffer-local 'ein:notebooklist-sort-order)
(put 'ein:notebooklist-sort-order 'permanent-local t)
(defmacro ein:make-sorting-widget (tag custom-var)
"Create the sorting widget."
;; assume that custom-var has type `choice' of `const's.
`(widget-create
'menu-choice :tag ,tag
:value ,custom-var
:notify (lambda (widget &rest _ignore)
(run-at-time 1 nil #'ein:notebooklist-reload)
(setq ,custom-var (widget-value widget)))
,@(mapcar (lambda (const)
`'(item :tag ,(third const) :value ,(fourth const)))
(rest (custom-variable-type custom-var)))))
(define-obsolete-variable-alias 'ein:notebooklist 'ein:%notebooklist% "0.1.2")
@ -160,7 +143,7 @@ Return nil if unclear what, if any, authentication applies."
(multiple-value-bind (password-p token) (ein:jupyter-crib-token url-or-port)
(multiple-value-bind (my-url-or-port my-token) (ein:jupyter-server-conn-info)
(cond ((eq password-p t) (read-passwd (format "Password for %s: " url-or-port)))
((and (stringp token) (eql password-p :json-false)) token)
((and (stringp token) (eq password-p :json-false)) token)
((equal url-or-port my-url-or-port) my-token)
(t nil)))))
@ -395,10 +378,10 @@ This function is called via `ein:notebook-after-rename-hook'."
(cl-defun ein:nblist--sort-group (group by-param order)
(sort group #'(lambda (x y)
(cond ((eql order :ascending)
(cond ((eq order :ascending)
(string-lessp (plist-get x by-param)
(plist-get y by-param)))
((eql order :descending)
((eq order :descending)
(string-greaterp (plist-get x by-param)
(plist-get y by-param)))))))
@ -412,11 +395,12 @@ This function is called via `ein:notebook-after-rename-hook'."
(nbs (ein:nblist--sort-group (cdr (assoc "notebook" groups))
sort-param
sort-order))
(files (ein:nblist--sort-group (-flatten-n 1 (-map #'cdr (-group-by
#'(lambda (x) (car (last (s-split "\\." (plist-get x :name)))))
(cdr (assoc "file" groups)))))
sort-param
sort-order)))
(files (ein:nblist--sort-group
(-flatten-n 1 (-map #'cdr (-group-by
#'(lambda (x) (car (last (split-string (plist-get x :name) "\\."))))
(cdr (assoc "file" groups)))))
sort-param
sort-order)))
(-concat dirs nbs files)))
(defun render-header (url-or-port &rest args)

View file

@ -1,13 +1,11 @@
(define-package "ein" "20200217.1252" "Emacs IPython Notebook"
(define-package "ein" "20200219.1501" "Emacs IPython Notebook"
'((emacs "25")
(websocket "20190620.338")
(anaphora "20180618")
(request "20200117.0")
(deferred "0.5")
(polymode "20190426.1729")
(kubernetes "20200114.0")
(dash "2.13.0")
(s "1.11.0")))
(polymode "20190714.0")
(dash "2.13.0")))
;; Local Variables:
;; no-byte-compile: t
;; End:

View file

@ -29,7 +29,6 @@
(require 'ein-jupyter)
(require 'ein-file)
(require 'ein-notebooklist)
(require 'ein-k8s)
(defcustom ein:process-jupyter-regexp "\\(jupyter\\|ipython\\)\\(-\\|\\s-+\\)note"
"Regexp by which we recognize notebook servers."
@ -209,10 +208,9 @@ is used instead. BUFFER-CALLBACK is called after notebook opened."
(defun ein:process-find-file-callback ()
"A callback function for `find-file-hook' to open notebook."
(interactive)
(cl-letf (((symbol-function 'ein:k8s-select-context) #'ignore))
(-when-let* ((filename buffer-file-name)
(match-p (string-match-p "\\.ipynb$" filename)))
(ein:process-open-notebook filename #'kill-buffer-if-not-modified))))
(-when-let* ((filename buffer-file-name)
(match-p (string-match-p "\\.ipynb$" filename)))
(ein:process-open-notebook filename #'kill-buffer-if-not-modified)))
(provide 'ein-process)

View file

@ -27,12 +27,10 @@
(require 'cc-mode)
(require 'json)
(require 's)
(require 'dash)
(require 'url)
(require 'deferred)
;;; Macros and core functions/variables
(defmacro ein:with-undo-disabled (&rest body)
@ -210,8 +208,7 @@ at point, i.e. any word before then \"(\", if it is present."
(setq url-or-port (format "http://localhost:%s" url-or-port)))
(let ((parsed-url (url-generic-parse-url url-or-port)))
(when (null (url-host parsed-url))
(setq url-or-port (concat (if (string= url-or-port (ein:k8s-service-url-or-port))
"http" "https") "://" url-or-port))
(setq url-or-port (concat "https://" url-or-port))
(setq parsed-url (url-generic-parse-url url-or-port)))
(when (or (string= (url-host parsed-url) "localhost")
(string= (url-host parsed-url) ein:url-localhost)
@ -685,7 +682,6 @@ Use `ein:log' for debugging and logging."
(when ein:enable-gc-adjust
(setq gc-cons-threshold current-gc-cons-threshold))))
;;; Git utilities
(defun ein:call-process (command &optional args)

View file

@ -1,312 +0,0 @@
;;; kubernetes-ast.el --- Rendering AST. -*- lexical-binding: t; -*-
;;; Commentary:
;; Implements an interpreter for a simple layout DSL for magit sections.
;;; Code:
(require 'cl-lib)
(require 'magit)
(require 'subr-x)
;; Derived component support.
(defconst kubernetes-ast--components (make-hash-table :test #'eq)
"A mapping from the name of a component to its interpretation function.
When traversing a rendering AST, any list beginning with a symbol
is interpreted as a component reference. That symbol is used to
look up an interpretation function in this table. That function is
applied to any remaining elements of that cons.
The result of a function in this hash-table should be a new
rendering AST, or a string value to be inserted directly.")
(defmacro kubernetes-ast-define-component (name arglist &rest body)
"Define a rendering component.
NAME is the name of the component, which may thereafter be
referenced directly in rendering ASTs.
ARGLIST is the arguments that must be supplied to construct the
component.
BODY is the definition of the component."
(declare (indent 2))
(cl-assert (symbolp name))
(cl-assert (listp arglist))
(let ((fname (intern (format "kubernetes-ast--generated--%s" name)))
(docstring (format "Auto-generated component constructor function.
Creates instances of %s components, which may be referred to as
such in rendering ASTs." name)))
`(progn
(cl-defun ,fname ,arglist ,docstring ,@body)
(puthash ',name #',fname kubernetes-ast--components))))
(kubernetes-ast-define-component line (inner-ast)
`(,inner-ast
(padding)))
(kubernetes-ast-define-component key-value (width key value)
(cl-assert (numberp width) t)
(cl-assert (<= 0 width) t)
(cl-assert (stringp key) t)
(cl-assert (stringp value) t)
(let* ((fmt-string (concat "%-" (number-to-string width) "s"))
(str (concat (propertize (format fmt-string (concat key ": ")) 'face 'magit-header-line)
value)))
(unless (string-blank-p (buffer-substring (line-beginning-position) (line-end-position)))
(newline))
`(copy-prop ,value (line ,str))))
(kubernetes-ast-define-component nav-prop (spec &rest inner-ast)
`(propertize (kubernetes-nav ,spec)
,inner-ast))
(kubernetes-ast-define-component copy-prop (copy-str &rest inner-ast)
(cl-assert (stringp copy-str) t)
`(propertize (kubernetes-copy ,copy-str)
,inner-ast))
;; Special operations.
(defun kubernetes-ast-put-delete-mark-on-line-at-pt (point)
(save-excursion
(goto-char point)
(goto-char (line-beginning-position))
(let* ((existing-props (text-properties-at (point)))
(props (append existing-props '(face kubernetes-delete-mark)))
(mark-str (concat (apply #'propertize "D" props)
(apply #'propertize " " existing-props))))
(cond
((member 'kubernetes-delete-mark existing-props)
nil)
((looking-at-p (rx bol space space))
(delete-char 2)
(insert mark-str))
(t
(insert mark-str))))))
;; AST interpreter.
(defconst kubernetes-ast--indentation-width 2)
(defconst kubernetes-ast--space ?\ )
(defsubst kubernetes-ast--indentation (indent-level)
(make-string (* indent-level kubernetes-ast--indentation-width) kubernetes-ast--space))
(defsubst kubernetes-ast--eval-string (s indent-level)
(let ((value (if (string-empty-p (buffer-substring (line-beginning-position) (point)))
(concat (kubernetes-ast--indentation indent-level) s)
s)))
(insert value)))
(defsubst kubernetes-ast--finalize-heading (start-pos)
;; This implementation is adapted from `magit-insert-heading'.
;; Apply heading face if no other face is set.
(let ((heading (buffer-substring start-pos (line-end-position))))
(unless (next-single-property-change 0 'face (concat "0" heading))
(add-text-properties start-pos (point) '(face magit-section-heading))))
(unless (bolp)
(insert ?\n))
;; Update containing section to point to this heading.
(setf (oref magit-insert-section--current content) (point-marker)))
(defsubst kubernetes-ast--finalize-delete-marks (start-pos)
(let ((end-line (line-number-at-pos)))
(save-excursion
(goto-char start-pos)
(kubernetes-ast-put-delete-mark-on-line-at-pt (point))
(while (< (line-number-at-pos) end-line)
(kubernetes-ast-put-delete-mark-on-line-at-pt (point))
(forward-line 1)))))
(defsubst kubernetes-ast--finalize-list-item (start-pos)
(save-excursion
(goto-char start-pos)
(goto-char (line-beginning-position))
(skip-chars-forward " ")
(unless (eq (char-after) ?-)
(delete-char -2)
(insert "- "))))
(defun kubernetes-ast--append-sentinel (instructions sentinel)
(append (list instructions) (list sentinel)))
(defun kubernetes-ast-eval (ast &optional indent-level)
"Evaluate AST as a set of instructions for inserting text into the current buffer."
;; The evaluator is implemented as a loop over an instruction stack. The
;; `instruction-stack' variable is a stack of AST instructions, the head of
;; which is the instruction to interpret. Its initial value is set to the
;; input to this function. After an instruction is interpreted, the item at
;; the top of the stack is popped. The loop ends when there are no more
;; instructions on the stack.
;;
;; If nested instructions are encountered in the AST, they are pushed onto the
;; stack, generally with a sentinel instruction to restore previous
;; interpreter state.
(let ((instruction-stack (list ast))
(indent-level (or indent-level 0)))
(while instruction-stack
(pcase (car instruction-stack)
;; Strings are inserted directly, possibly with indentation.
((and (pred stringp) s)
(kubernetes-ast--eval-string s indent-level)
(!cdr instruction-stack))
;; Padding gets some special error checking to make sure it has no inner
;; AST, since I get `padding' and `indent' mixed up all the time.
((and `(padding . ,_rest) (guard _rest))
(error "Padding takes no arguments"))
(`(padding)
(newline)
(!cdr instruction-stack))
;; Indentation
;;
;; The current indentation level is tracked by the interpreter. When an
;; `indent' directive is encountered, the indent level is incremented
;; and the inner AST is pushed to the stack with a sentinel appended.
;; When the sentinel is encountered, the indentation level is decreased.
(`(indent . ,inner-ast)
(let ((next (kubernetes-ast--append-sentinel inner-ast 'kubernetes-ast--indent-sentinel)))
(setq indent-level (1+ indent-level))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`kubernetes-ast--indent-sentinel
(setq indent-level (1- indent-level))
(!cdr instruction-stack))
;; Properties
;;
;; To propertize some inserted text, the inner AST is pushed to the
;; stack with a sentinel appended. The sentinel records the properties
;; to apply and the start position of the span. Once the sentinel is
;; encountered, the end position of the span is known and properties can
;; be applied.
(`(propertize ,spec . ,inner-ast)
(let ((next (kubernetes-ast--append-sentinel inner-ast `(kubernetes-ast--propertize-sentinel ,(point) ,spec))))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`(kubernetes-ast--propertize-sentinel ,start ,spec)
(add-text-properties start (point) spec)
(!cdr instruction-stack))
;; Deletion marks
;;
;; Deletion marks are applied to every line of the inner AST, so the
;; inner AST is pushed to the stack with a sentinel that records the
;; start position. Once the sentinel is encountered, the range of lines
;; that must be modified is known and the marks are written.
(`(mark-for-delete . ,inner-ast)
(let ((next (kubernetes-ast--append-sentinel inner-ast `(kubernetes-ast--mark-for-delete-sentinel . ,(point)))))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`(kubernetes-ast--mark-for-delete-sentinel . ,start)
(kubernetes-ast--finalize-delete-marks start)
(!cdr instruction-stack))
;; Bulleted lists
;;
;; A bulleted list is decomposed into a sequence of instructions, each
;; of which tracks its buffer positions using sentinel values.
;;
;; The bullet group is indented, and each item's start position is
;; recorded in a sentinel value. When an item's sentinel is encountered,
;; the item's dash is written to the buffer.
(`(list . ,items)
(let ((next `(indent ,@(--map `(kubernetes-ast--list-item . ,it) items))))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`(kubernetes-ast--list-item . ,inner-ast)
(let ((next (kubernetes-ast--append-sentinel inner-ast `(kubernetes-ast--list-item-sentinel . ,(point)))))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`(kubernetes-ast--list-item-sentinel . ,start)
(kubernetes-ast--finalize-list-item start)
(!cdr instruction-stack))
;; Headings
;;
;; Heading insertion requires interpretation of an inner AST to build
;; the heading text. A special sentinel is appended to the inner AST
;; that tells the interpreter to finalise the heading after interpreting
;; the inner value.
(`(heading ,inner-ast)
(unless magit-insert-section--current (error "Eval AST: Inserting a heading, but not in a section"))
(let ((next (kubernetes-ast--append-sentinel inner-ast `(kubernetes-ast--heading-sentinel . ,(point)))))
(!cdr instruction-stack)
(!cons next instruction-stack)))
(`(kubernetes-ast--heading-sentinel . ,start-pos)
(kubernetes-ast--finalize-heading start-pos)
(!cdr instruction-stack))
;; Sections
;;
;; KLUDGE: The section insertion logic in magit has complex state. It's
;; easier just to evaluate recursively than try to reproduce that logic
;; in the interpreter. This is safe so long as section nesting doesn't
;; approach `max-lisp-eval-depth'.
(`(section (,sym ,hide) . ,inner)
(!cdr instruction-stack)
(eval `(magit-insert-section (,sym nil ,hide)
(kubernetes-ast-eval ',inner ,indent-level))))
;; Custom components
;;
;; If the current instruction is a list and its head is a symbol, look
;; it up in the component definition table. If the lookup succeeds,
;; evaluate the component's constructor function to derive an AST, and
;; push that AST onto the stack.
((and `(,component . ,args)
(guard component)
(guard (symbolp component)))
(!cdr instruction-stack)
(if-let (constructor (gethash component kubernetes-ast--components))
(!cons (apply constructor args) instruction-stack)
(error "Component not defined: %s" component)))
;; Lists of instructions
;;
;; If the list being scrutinised does not begin with a symbol, it is
;; assumed to be a sequence of instructions. The items are pushed to the
;; stack.
((and (pred listp) actions)
(!cdr instruction-stack)
(setq instruction-stack (append actions instruction-stack)))
;; Heck, you've done the interpreter a frighten.
(other
(message "Stack: %s" instruction-stack)
(error "Unknown AST instruction: %s" other))))))
(provide 'kubernetes-ast)
;;; kubernetes-ast.el ends here

View file

@ -1,518 +0,0 @@
;;; kubernetes-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "kubernetes-ast" "kubernetes-ast.el" (0 0 0
;;;;;; 0))
;;; Generated autoloads from kubernetes-ast.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-ast" '("kubernetes-ast-")))
;;;***
;;;### (autoloads nil "kubernetes-commands" "kubernetes-commands.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-commands.el
(autoload 'kubernetes-mark-for-delete "kubernetes-commands" "\
Mark the thing at POINT for deletion, then advance to the next line.
\(fn POINT)" t nil)
(autoload 'kubernetes-unmark "kubernetes-commands" "\
Unmark the thing at POINT, then advance to the next line.
\(fn POINT)" t nil)
(autoload 'kubernetes-unmark-all "kubernetes-commands" "\
Unmark everything in the buffer.
\(fn)" t nil)
(autoload 'kubernetes-execute-marks "kubernetes-commands" "\
Action all marked items in the buffer.
\(fn)" t nil)
(autoload 'kubernetes-copy-thing-at-point "kubernetes-commands" "\
Perform a context-sensitive copy action.
Inspects the `kubernetes-copy' text property at POINT to determine
what to copy.
\(fn POINT)" t nil)
(autoload 'kubernetes-refresh "kubernetes-commands" "\
Force Kubernetes buffers to redraw.
With optional argument VERBOSE, log status changes.
\(fn &optional VERBOSE)" t nil)
(autoload 'kubernetes-navigate "kubernetes-commands" "\
Perform a context-sensitive navigation action.
STATE is the current application state.
Inspecs the `kubernetes-nav' text property at POINT to determine
how to navigate. If that property is not found, attempt to toggle
the magit section at point.
\(fn POINT STATE)" t nil)
(autoload 'kubernetes-describe-dwim "kubernetes-commands" "\
Describe the thing at point.
THING must be a valid target for `kubectl describe'.
\(fn THING)" t nil)
(autoload 'kubernetes-describe-pod "kubernetes-commands" "\
Display a buffer for describing a pod.
POD-NAME is the name of the pod to describe.
\(fn POD-NAME)" t nil)
(autoload 'kubernetes-exec-into "kubernetes-commands" "\
Open a terminal for execting into a pod.
POD-NAME is the name of the pod to exec into.
ARGS are additional args to pass to kubectl.
EXEC-COMMAND is the command to run in the container.
STATE is the current application state.
Should be invoked via command `kubernetes-logs-popup'.
\(fn POD-NAME ARGS EXEC-COMMAND STATE)" t nil)
(autoload 'kubernetes-set-namespace "kubernetes-commands" "\
Set the namespace to query to NS.
Overrides the namespace settings for the current context.
STATE is the current application state.
\(fn NS STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-commands" '("kubernetes-")))
;;;***
;;;### (autoloads nil "kubernetes-configmaps" "kubernetes-configmaps.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-configmaps.el
(autoload 'kubernetes-display-configmap "kubernetes-configmaps" "\
Display information for a configmap in a new window.
STATE is the current application state.
CONFIGMAP-NAME is the name of the configmap to display.
\(fn CONFIGMAP-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-configmaps" '("kubernetes-configmaps-")))
;;;***
;;;### (autoloads nil "kubernetes-contexts" "kubernetes-contexts.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-contexts.el
(autoload 'kubernetes-display-config "kubernetes-contexts" "\
Display information for CONFIG in a new window.
\(fn CONFIG)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-contexts" '("kubernetes-")))
;;;***
;;;### (autoloads nil "kubernetes-deployments" "kubernetes-deployments.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-deployments.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-deployments" '("kubernetes-d")))
;;;***
;;;### (autoloads nil "kubernetes-errors" "kubernetes-errors.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-errors.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-errors" '("kubernetes-errors-render")))
;;;***
;;;### (autoloads nil "kubernetes-ingress" "kubernetes-ingress.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-ingress.el
(autoload 'kubernetes-display-ingress "kubernetes-ingress" "\
Display information for a ingress in a new window.
STATE is the current application state.
INGRESS-NAME is the name of the ingress to display.
\(fn INGRESS-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-ingress" '("kubernetes-ingress-")))
;;;***
;;;### (autoloads nil "kubernetes-jobs" "kubernetes-jobs.el" (0 0
;;;;;; 0 0))
;;; Generated autoloads from kubernetes-jobs.el
(autoload 'kubernetes-display-job "kubernetes-jobs" "\
Display information for a job in a new window.
STATE is the current application state.
JOB-NAME is the name of the job to display.
\(fn JOB-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-jobs" '("kubernetes-jobs-")))
;;;***
;;;### (autoloads nil "kubernetes-kubectl" "kubernetes-kubectl.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-kubectl.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-kubectl" '("kubernetes-kubectl")))
;;;***
;;;### (autoloads nil "kubernetes-labels" "kubernetes-labels.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-labels.el
(autoload 'kubernetes-show-pods-for-label "kubernetes-labels" "\
Display a buffer for pods matching a label.
LABEL-QUERY is a string used to match pods.
\(fn LABEL-QUERY)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-labels" '("kubernetes-labels--")))
;;;***
;;;### (autoloads nil "kubernetes-logs" "kubernetes-logs.el" (0 0
;;;;;; 0 0))
;;; Generated autoloads from kubernetes-logs.el
(autoload 'kubernetes-logs-inspect-line "kubernetes-logs" "\
Show detail for the log line at POS.
\(fn POS)" t nil)
(autoload 'kubernetes-logs-previous-line "kubernetes-logs" "\
Move backward and inspect the line at point.
\(fn)" t nil)
(autoload 'kubernetes-logs-forward-line "kubernetes-logs" "\
Move forward and inspect the line at point.
\(fn)" t nil)
(autoload 'kubernetes-logs-follow "kubernetes-logs" "\
Open a streaming logs buffer for a pod.
POD-NAME is the name of the pod to log.
ARGS are additional args to pass to kubectl.
STATE is the current application state.
\(fn POD-NAME ARGS STATE)" t nil)
(autoload 'kubernetes-logs-fetch-all "kubernetes-logs" "\
Open a streaming logs buffer for POD.
POD-NAME is the name of the pod to log.
ARGS are additional args to pass to kubectl.
STATE is the current application state
\(fn POD-NAME ARGS STATE)" t nil)
(defvar kubernetes-logs-mode-map (let ((keymap (make-sparse-keymap))) (define-key keymap (kbd "n") #'kubernetes-logs-forward-line) (define-key keymap (kbd "p") #'kubernetes-logs-previous-line) (define-key keymap (kbd "RET") #'kubernetes-logs-inspect-line) keymap) "\
Keymap for `kubernetes-logs-mode'.")
(autoload 'kubernetes-logs-mode "kubernetes-logs" "\
Mode for displaying and inspecting Kubernetes logs.
\\<kubernetes-logs-mode-map>Type \\[kubernetes-logs-inspect-line] to open the line at point in a new buffer.
\\{kubernetes-logs-mode-map}
\(fn)" t nil)
(defvar kubernetes-log-line-mode-map (let ((keymap (make-sparse-keymap))) (define-key keymap (kbd "n") #'kubernetes-logs-forward-line) (define-key keymap (kbd "p") #'kubernetes-logs-previous-line) keymap) "\
Keymap for `kubernetes-log-line-mode'.")
(autoload 'kubernetes-log-line-mode "kubernetes-logs" "\
Mode for inspecting Kubernetes log lines.
\\{kubernetes-log-line-mode-map}
\(fn)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-logs" '("kubernetes-logs--log-line-buffer-for-string")))
;;;***
;;;### (autoloads nil "kubernetes-modes" "kubernetes-modes.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from kubernetes-modes.el
(autoload 'kubernetes-display-thing-mode "kubernetes-modes" "\
Mode for inspecting a Kubernetes object.
\\{kubernetes-display-thing-mode-map}
\(fn)" t nil)
(defvar kubernetes-mode-map (let ((keymap (make-sparse-keymap))) (define-key keymap (kbd "p") #'magit-section-backward) (define-key keymap (kbd "n") #'magit-section-forward) (define-key keymap (kbd "M-p") #'magit-section-backward-sibling) (define-key keymap (kbd "M-n") #'magit-section-forward-sibling) (define-key keymap (kbd "C-i") #'magit-section-toggle) (define-key keymap (kbd "^") #'magit-section-up) (define-key keymap [tab] #'magit-section-toggle) (define-key keymap [C-tab] #'magit-section-cycle) (define-key keymap [M-tab] #'magit-section-cycle-diffs) (define-key keymap [S-tab] #'magit-section-cycle-global) (define-key keymap (kbd "q") #'quit-window) (define-key keymap (kbd "RET") #'kubernetes-navigate) (define-key keymap (kbd "M-w") #'kubernetes-copy-thing-at-point) (define-key keymap (kbd "h") #'describe-mode) (define-key keymap (kbd "?") #'kubernetes-overview-popup) (define-key keymap (kbd "c") #'kubernetes-config-popup) (define-key keymap (kbd "d") #'kubernetes-describe-popup) (define-key keymap (kbd "D") #'kubernetes-mark-for-delete) (define-key keymap (kbd "e") #'kubernetes-exec-popup) (define-key keymap (kbd "g") #'kubernetes-refresh) (define-key keymap (kbd "l") #'kubernetes-logs-popup) (define-key keymap (kbd "L") #'kubernetes-labels-popup) (define-key keymap (kbd "u") #'kubernetes-unmark) (define-key keymap (kbd "U") #'kubernetes-unmark-all) (define-key keymap (kbd "x") #'kubernetes-execute-marks) keymap) "\
Keymap for `kubernetes-mode'. This is the base keymap for all derived modes.")
(autoload 'kubernetes-mode "kubernetes-modes" "\
Base mode for Kubernetes modes.
\\{kubernetes-mode-map}
\(fn)" t nil)
;;;***
;;;### (autoloads nil "kubernetes-namespaces" "kubernetes-namespaces.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-namespaces.el
(autoload 'kubernetes-display-namespace "kubernetes-namespaces" "\
Display information for a namespace in a new window.
STATE is the current application state.
NAMESPACE-NAME is the name of the namespace to display.
\(fn NAMESPACE-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-namespaces" '("kubernetes-namespaces--read-name")))
;;;***
;;;### (autoloads nil "kubernetes-nodes" "kubernetes-nodes.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from kubernetes-nodes.el
(autoload 'kubernetes-display-node "kubernetes-nodes" "\
Display information for a node in a new window.
STATE is the current application state.
NODE-NAME is the name of the node to display.
\(fn NODE-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-nodes" '("kubernetes-nodes--")))
;;;***
;;;### (autoloads nil "kubernetes-overview" "kubernetes-overview.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-overview.el
(autoload 'kubernetes-overview-mode "kubernetes-overview" "\
Mode for working with Kubernetes overview.
\\<kubernetes-overview-mode-map>Type \\[kubernetes-overview-set-sections] to choose which resources to display.
Type \\[kubernetes-mark-for-delete] to mark an object for deletion, and \\[kubernetes-execute-marks] to execute.
Type \\[kubernetes-unmark] to unmark the object at point, or \\[kubernetes-unmark-all] to unmark all objects.
Type \\[kubernetes-navigate] to inspect the object on the current line.
Type \\[kubernetes-copy-thing-at-point] to copy the thing at point.
Type \\[kubernetes-refresh] to refresh the buffer.
\\{kubernetes-overview-mode-map}
\(fn)" t nil)
(autoload 'kubernetes-overview "kubernetes-overview" "\
Display an overview buffer for Kubernetes.
\(fn)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-overview" '("kubernetes-overview-")))
;;;***
;;;### (autoloads nil "kubernetes-pod-line" "kubernetes-pod-line.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-pod-line.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-pod-line" '("kubernetes-pod-line-ok-p")))
;;;***
;;;### (autoloads nil "kubernetes-pods" "kubernetes-pods.el" (0 0
;;;;;; 0 0))
;;; Generated autoloads from kubernetes-pods.el
(autoload 'kubernetes-display-pod "kubernetes-pods" "\
Display information for a pod in a new window.
STATE is the current application state.
POD-NAME is the name of the pod to display.
\(fn POD-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-pods" '("kubernetes-pods-")))
;;;***
;;;### (autoloads nil "kubernetes-popups" "kubernetes-popups.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-popups.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-popups" '("kubernetes-")))
;;;***
;;;### (autoloads nil "kubernetes-process" "kubernetes-process.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-process.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-process" '("kubernetes-process-")))
;;;***
;;;### (autoloads nil "kubernetes-props" "kubernetes-props.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from kubernetes-props.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-props" '("kubernetes-props")))
;;;***
;;;### (autoloads nil "kubernetes-secrets" "kubernetes-secrets.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-secrets.el
(autoload 'kubernetes-display-secret "kubernetes-secrets" "\
Display information for a secret in a new window.
STATE is the current application state.
SECRET-NAME is the name of the secret to display.
\(fn SECRET-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-secrets" '("kubernetes-secrets-")))
;;;***
;;;### (autoloads nil "kubernetes-services" "kubernetes-services.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-services.el
(autoload 'kubernetes-display-service "kubernetes-services" "\
Display information for a service in a new window.
STATE is the current application state.
SERVICE-NAME is the name of the service to display.
\(fn SERVICE-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-services" '("kubernetes-services-")))
;;;***
;;;### (autoloads nil "kubernetes-state" "kubernetes-state.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from kubernetes-state.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-state" '("kubernetes-state")))
;;;***
;;;### (autoloads nil "kubernetes-statefulsets" "kubernetes-statefulsets.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-statefulsets.el
(autoload 'kubernetes-display-statefulset "kubernetes-statefulsets" "\
Display information for a statefulset in a new window.
STATE is the current application state.
STATEFULSET-NAME is the name of the statefulset to display.
\(fn STATEFULSET-NAME STATE)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-statefulsets" '("kubernetes-statefulsets-")))
;;;***
;;;### (autoloads nil "kubernetes-timers" "kubernetes-timers.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from kubernetes-timers.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-timers" '("kubernetes-timers-")))
;;;***
;;;### (autoloads nil "kubernetes-utils" "kubernetes-utils.el" (0
;;;;;; 0 0 0))
;;; Generated autoloads from kubernetes-utils.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-utils" '("kubernetes-")))
;;;***
;;;### (autoloads nil "kubernetes-vars" "kubernetes-vars.el" (0 0
;;;;;; 0 0))
;;; Generated autoloads from kubernetes-vars.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-vars" '("kubernetes-")))
;;;***
;;;### (autoloads nil "kubernetes-yaml" "kubernetes-yaml.el" (0 0
;;;;;; 0 0))
;;; Generated autoloads from kubernetes-yaml.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "kubernetes-yaml" '("kubernetes-yaml-")))
;;;***
;;;### (autoloads nil nil ("kubernetes-loading-container.el" "kubernetes-pkg.el"
;;;;;; "kubernetes.el") (0 0 0 0))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; kubernetes-autoloads.el ends here

View file

@ -1,398 +0,0 @@
;;; kubernetes-commands.el --- Interactive commands for Kubernetes modes. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'kubernetes-ast)
(require 'kubernetes-modes)
(require 'kubernetes-popups)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(autoload 'kubernetes-configmaps-delete-marked "kubernetes-configmaps")
(autoload 'kubernetes-deployments-delete-marked "kubernetes-deployments")
(autoload 'kubernetes-statefulsets-delete-marked "kubernetes-statefulsets")
(autoload 'kubernetes-ingress-delete-marked "kubernetes-ingress")
(autoload 'kubernetes-display-config "kubernetes-contexts")
(autoload 'kubernetes-display-configmap "kubernetes-configmaps")
(autoload 'kubernetes-display-deployment "kubernetes-deployments")
(autoload 'kubernetes-display-statefulset "kubernetes-statefulsets")
(autoload 'kubernetes-display-ingress "kubernetes-ingress")
(autoload 'kubernetes-display-node "kubernetes-nodes")
(autoload 'kubernetes-display-job "kubernetes-jobs")
(autoload 'kubernetes-display-namespace "kubernetes-namespaces")
(autoload 'kubernetes-display-pod "kubernetes-pods")
(autoload 'kubernetes-display-secret "kubernetes-secrets")
(autoload 'kubernetes-display-service "kubernetes-services")
(autoload 'kubernetes-jobs-delete-marked "kubernetes-jobs")
(autoload 'kubernetes-pods-delete-marked "kubernetes-pods")
(autoload 'kubernetes-secrets-delete-marked "kubernetes-secrets")
(autoload 'kubernetes-services-delete-marked "kubernetes-services")
(autoload 'kubernetes-show-pods-for-label "kubernetes-labels")
;; Mark management
;;;###autoload
(defun kubernetes-mark-for-delete (point)
"Mark the thing at POINT for deletion, then advance to the next line."
(interactive "d")
(pcase (get-text-property point 'kubernetes-nav)
(`(:pod-name ,name)
(kubernetes-state-mark-pod name))
(`(:configmap-name ,name)
(kubernetes-state-mark-configmap name))
(`(:ingress-name ,name)
(kubernetes-state-mark-ingress name))
(`(:job-name ,name)
(kubernetes-state-mark-job name))
(`(:secret-name ,name)
(kubernetes-state-mark-secret name))
(`(:service-name ,name)
(kubernetes-state-mark-service name))
(`(:deployment-name ,name)
(kubernetes-state-mark-deployment name))
(`(:statefulset-name ,name)
(kubernetes-state-mark-statefulset name))
(_
(user-error "Nothing here can be marked")))
(let ((inhibit-read-only t))
(kubernetes-ast-put-delete-mark-on-line-at-pt point))
(magit-section-forward))
;;;###autoload
(defun kubernetes-unmark (point)
"Unmark the thing at POINT, then advance to the next line."
(interactive "d")
(pcase (get-text-property point 'kubernetes-nav)
(`(:pod-name ,name)
(kubernetes-state-unmark-pod name))
(`(:configmap-name ,name)
(kubernetes-state-unmark-configmap name))
(`(:ingress-name ,name)
(kubernetes-state-unmark-ingress name))
(`(:job-name ,name)
(kubernetes-state-unmark-job name))
(`(:secret-name ,name)
(kubernetes-state-unmark-secret name))
(`(:service-name ,name)
(kubernetes-state-unmark-service name))
(`(:deployment-name ,name)
(kubernetes-state-unmark-deployment name))
(`(:statefulset-name ,name)
(kubernetes-state-unmark-statefulset name)))
(kubernetes-state-trigger-redraw)
(goto-char point)
(magit-section-forward))
;;;###autoload
(defun kubernetes-unmark-all ()
"Unmark everything in the buffer."
(interactive)
(kubernetes-state-unmark-all)
(let ((pt (point)))
(kubernetes-state-trigger-redraw)
(goto-char pt)))
;;;###autoload
(defun kubernetes-execute-marks ()
"Action all marked items in the buffer."
(interactive)
(let ((state (kubernetes-state)))
(let ((n (length (kubernetes-state-marked-pods state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s pod%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-pods-delete-marked state)))
(let ((n (length (kubernetes-state-marked-configmaps state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s configmap%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-configmaps-delete-marked state)))
(let ((n (length (kubernetes-state-marked-ingress state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s ingress%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-ingress-delete-marked state)))
(let ((n (length (kubernetes-state-marked-secrets state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s secret%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-secrets-delete-marked state)))
(let ((n (length (kubernetes-state-marked-deployments state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s deployment%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-deployments-delete-marked state)))
(let ((n (length (kubernetes-state-marked-statefulsets state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s statefulsets%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-statefulsets-delete-marked state)))
(let ((n (length (kubernetes-state-marked-jobs state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s job%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-jobs-delete-marked state)))
(let ((n (length (kubernetes-state-marked-services state))))
(when (and (not (zerop n))
(y-or-n-p (format "Delete %s service%s? " n (if (equal 1 n) "" "s"))))
(kubernetes-services-delete-marked state))))
(kubernetes-unmark-all))
;; Misc commands
;;;###autoload
(defun kubernetes-copy-thing-at-point (point)
"Perform a context-sensitive copy action.
Inspects the `kubernetes-copy' text property at POINT to determine
what to copy."
(interactive "d")
(when-let (s (get-text-property point 'kubernetes-copy))
(kill-new s)
;; Print a user-friendly message for feedback.
(let ((n-lines 1) (first-line nil))
(with-temp-buffer
(insert s)
(goto-char (point-min))
(setq first-line (buffer-substring (line-beginning-position) (line-end-position)))
(while (search-forward "\n" nil t)
(setq n-lines (1+ n-lines))))
(let ((ellipsized (kubernetes-utils-ellipsize first-line 70)))
(if (< 1 n-lines)
(message "Copied %s lines, starting with: %s" n-lines ellipsized)
(message "Copied: %s" ellipsized))))))
;;;###autoload
(defun kubernetes-refresh (&optional verbose)
"Force Kubernetes buffers to redraw.
With optional argument VERBOSE, log status changes."
(interactive "p")
(run-hook-with-args 'kubernetes-poll-hook verbose)
(kubernetes-state-trigger-redraw))
;;;###autoload
(defun kubernetes-navigate (point state)
"Perform a context-sensitive navigation action.
STATE is the current application state.
Inspecs the `kubernetes-nav' text property at POINT to determine
how to navigate. If that property is not found, attempt to toggle
the magit section at point."
(interactive (list (point) (kubernetes-state)))
(pcase (get-text-property point 'kubernetes-nav)
(:display-config
(kubernetes-display-config (alist-get 'config state)))
(`(:configmap-name ,configmap-name)
(kubernetes-display-configmap configmap-name state))
(`(:service-name ,service-name)
(kubernetes-display-service service-name state))
(`(:deployment-name ,deployment-name)
(kubernetes-display-deployment deployment-name state))
(`(:statefulset-name ,statefulset-name)
(kubernetes-display-statefulset statefulset-name state))
(`(:ingress-name ,ingress-name)
(kubernetes-display-ingress ingress-name state))
(`(:node-name ,node-name)
(kubernetes-display-node node-name state))
(`(:job-name ,job-name)
(kubernetes-display-job job-name state))
(`(:secret-name ,secret-name)
(kubernetes-display-secret secret-name state))
(`(:namespace-name ,namespace-name)
(kubernetes-display-namespace namespace-name state))
(`(:pod-name ,pod-name)
(kubernetes-display-pod pod-name state))
(`(:selector ,selector)
(kubernetes-show-pods-for-label selector))
(_
(when-let (section (get-text-property (point) 'magit-section))
(magit-section-toggle section)))))
(defun kubernetes--describable-thing-at-pt ()
(save-excursion
(back-to-indentation)
(get-text-property (point) 'kubernetes-nav)))
;;;###autoload
(defun kubernetes-describe-dwim (thing)
"Describe the thing at point.
THING must be a valid target for `kubectl describe'."
(interactive (list (kubernetes--describable-thing-at-pt)))
(pcase thing
(`(:pod-name ,pod-name)
(kubernetes-describe-pod pod-name))
(_
(user-error "Nothing at point to describe"))))
;;;###autoload
(defun kubernetes-describe-pod (pod-name)
"Display a buffer for describing a pod.
POD-NAME is the name of the pod to describe."
(interactive (list (or (kubernetes-utils-maybe-pod-name-at-point) (kubernetes-utils-read-pod-name (kubernetes-state)))))
(let ((buf (get-buffer-create kubernetes-pod-buffer-name))
(marker (make-marker)))
(with-current-buffer buf
(kubernetes-display-thing-mode)
(let ((inhibit-read-only t))
(erase-buffer)
(set-marker marker (point))
(insert (propertize "Loading..." 'face 'magit-dimmed))))
(let* ((populate-buffer (lambda (s)
(with-current-buffer (marker-buffer marker)
(setq-local tab-width 8)
(let ((inhibit-read-only t)
(inhibit-redisplay t))
(erase-buffer)
(insert "---\n")
(insert s)
(untabify (point-min) (point-max))
(goto-char (point-min))))))
(proc (kubernetes-kubectl-describe-pod kubernetes-props
(kubernetes-state)
pod-name
populate-buffer)))
(with-current-buffer buf
(add-hook 'kill-buffer-hook (lambda () (kubernetes-process-kill-quietly proc)) nil t)))
(select-window (display-buffer buf))
buf))
;;;###autoload
(defun kubernetes-exec-into (pod-name args exec-command state)
"Open a terminal for execting into a pod.
POD-NAME is the name of the pod to exec into.
ARGS are additional args to pass to kubectl.
EXEC-COMMAND is the command to run in the container.
STATE is the current application state.
Should be invoked via command `kubernetes-logs-popup'."
(interactive (let* ((state (kubernetes-state))
(pod-name (or (kubernetes-utils-maybe-pod-name-at-point) (kubernetes-utils-read-pod-name state)))
(command
(let ((cmd (string-trim (read-string (format "Command (default: %s): " kubernetes-default-exec-command)
nil 'kubernetes-exec-history))))
(if (string-empty-p cmd) kubernetes-default-exec-command cmd))))
(list pod-name (kubernetes-exec-arguments) command state)))
(let* ((command-args (append (list "exec") (kubernetes-kubectl--flags-from-state (kubernetes-state))
args
(when-let (ns (kubernetes-state-current-namespace state))
(list (format "--namespace=%s" ns)))
(list pod-name exec-command)))
(interactive-tty (member "-t" args))
(buf
(if interactive-tty
(kubernetes-utils-term-buffer-start kubernetes-exec-buffer-name
kubernetes-kubectl-executable
command-args)
(kubernetes-utils-process-buffer-start kubernetes-exec-buffer-name
#'kubernetes-mode
kubernetes-kubectl-executable
command-args))))
(when (and interactive-tty kubernetes-clean-up-interactive-exec-buffers)
(set-process-sentinel (get-buffer-process buf) #'kubernetes-process-kill-quietly))
(select-window (display-buffer buf))))
;; View management
(defun kubernetes-commands-display-buffer-fullframe (buffer)
(let ((display-fn
(lambda (buffer alist)
(when-let (window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist)))
(delete-other-windows window)
window))))
(display-buffer buffer (list display-fn))))
(defun kubernetes-commands-display-buffer (buffer)
(let ((window (funcall kubernetes-commands-display-buffer-function buffer)))
(when kubernetes-commands-display-buffer-select
(select-frame-set-input-focus
(window-frame (select-window window))))))
;; Config management
;;;###autoload
(defun kubernetes-set-namespace (ns state)
"Set the namespace to query to NS.
Overrides the namespace settings for the current context.
STATE is the current application state."
(interactive
(let ((state (kubernetes-state)))
(list (completing-read "Use namespace: " (kubernetes--namespace-names state) nil t)
state)))
(kubernetes-process-kill-polling-processes)
(kubernetes-state-clear)
(goto-char (point-min))
;; State for the context and view should be preserved.
(kubernetes-state-update-config (kubernetes-state-config state))
(kubernetes-state-update-current-namespace ns)
(kubernetes-state-update-overview-sections (kubernetes-state-overview-sections state))
(kubernetes-state-trigger-redraw))
(defun kubernetes--namespace-names (state)
(-let* ((config (or (kubernetes-state-namespaces state) (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-namespaces)))
((&alist 'items items) config))
(-map (-lambda ((&alist 'metadata (&alist 'name name))) name) items)))
(defun kubernetes-use-context (context)
"Switch Kubernetes context refresh the pods buffer.
CONTEXT is the name of a context as a string."
(interactive (list (completing-read "Context: " (kubernetes--context-names (kubernetes-state)) nil t)))
(kubernetes-process-kill-polling-processes)
(let ((state (kubernetes-state)))
(kubernetes-state-clear)
(kubernetes-state-update-overview-sections (kubernetes-state-overview-sections state)))
(kubernetes-state-trigger-redraw)
(when-let (buf (get-buffer kubernetes-overview-buffer-name))
(with-current-buffer buf
(goto-char (point-min))))
(let ((state (kubernetes-state)))
(kubernetes-kubectl-config-use-context
kubernetes-props
state
context
(lambda (_)
(when kubernetes-default-overview-namespace
(kubernetes-set-namespace kubernetes-default-overview-namespace
state))
(kubernetes-state-trigger-redraw)))))
(defun kubernetes--context-names (state)
(-let* ((config (or (kubernetes-state-config state) (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-config-view)))
((&alist 'contexts contexts) config))
(--map (alist-get 'name it) contexts)))
(provide 'kubernetes-commands)
;;; kubernetes-commands.el ends here

View file

@ -1,137 +0,0 @@
;;; kubernetes-configmaps.el --- Rendering for Kubernetes configmaps. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-ast)
(require 'kubernetes-loading-container)
(require 'kubernetes-modes)
(require 'kubernetes-process)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-yaml)
;; Components
(defconst kubernetes-configmaps--column-heading
["%-45s %6s %6s" "Name Data Age"])
(kubernetes-ast-define-component configmap-detail (configmap)
(-let [(&alist 'metadata (&alist 'namespace ns 'creationTimestamp time)) configmap]
`((section (namespace nil)
(nav-prop (:namespace-name ,ns)
(key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace))))
(key-value 12 "Created" ,time))))
(kubernetes-ast-define-component configmap-line (state configmap)
(-let* ((current-time (kubernetes-state-current-time state))
(pending-deletion (kubernetes-state-configmaps-pending-deletion state))
(marked-configmaps (kubernetes-state-marked-configmaps state))
((&alist 'data data
'metadata (&alist 'name name 'creationTimestamp created-time))
configmap)
([fmt] kubernetes-configmaps--column-heading)
(list-fmt (split-string fmt))
(line `(line ,(concat
;; Name
(format (pop list-fmt) (kubernetes-utils-ellipsize name 45))
" "
;; Data
(propertize (format (pop list-fmt) (seq-length data)) 'face 'magit-dimmed)
" "
;; Age
(let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
(propertize (format (pop list-fmt) (kubernetes-utils-time-diff-string start current-time))
'face 'magit-dimmed))))))
`(nav-prop (:configmap-name ,name)
(copy-prop ,name
,(cond
((member name pending-deletion)
`(propertize (face kubernetes-pending-deletion) ,line))
((member name marked-configmaps)
`(mark-for-delete ,line))
(t
line))))))
(kubernetes-ast-define-component configmap (state configmap)
`(section (,(intern (kubernetes-state-resource-name configmap)) t)
(heading (configmap-line ,state ,configmap))
(section (details nil)
(indent
(configmap-detail ,configmap)
(padding)))))
(kubernetes-ast-define-component configmaps-list (state &optional hidden)
(-let (((&alist 'items configmaps) (kubernetes-state-configmaps state))
([fmt labels] kubernetes-configmaps--column-heading))
`(section (configmaps-container ,hidden)
(header-with-count "Configmaps" ,configmaps)
(indent
(columnar-loading-container ,configmaps
,(propertize
(apply #'format fmt (split-string labels))
'face
'magit-section-heading)
,(--map `(configmap ,state ,it) configmaps)))
(padding))))
;; Requests and state management
(kubernetes-state-define-refreshers configmaps)
(defun kubernetes-configmaps-delete-marked (state)
(let ((names (kubernetes-state-marked-configmaps state)))
(dolist (name names)
(kubernetes-state-delete-configmap name)
(kubernetes-kubectl-delete-configmap kubernetes-props state name
(lambda (_)
(message "Deleting configmap %s succeeded." name))
(lambda (_)
(message "Deleting configmap %s failed" name)
(kubernetes-state-mark-configmap name))))
(kubernetes-state-trigger-redraw)))
;; Displaying configmaps.
(defun kubernetes-configmaps--read-name (state)
"Read a configmap name from the user.
STATE is the current application state.
Update the configmap state if it not set yet."
(-let* (((&alist 'items configmaps)
(or (kubernetes-state-configmaps state)
(progn
(message "Getting configmaps...")
(let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-configmaps)))
(kubernetes-state-update-configmaps response)
response))))
(configmaps (append configmaps nil))
(names (-map #'kubernetes-state-resource-name configmaps)))
(completing-read "Configmap: " names nil t)))
;;;###autoload
(defun kubernetes-display-configmap (configmap-name state)
"Display information for a configmap in a new window.
STATE is the current application state.
CONFIGMAP-NAME is the name of the configmap to display."
(interactive (let ((state (kubernetes-state)))
(list (kubernetes-configmaps--read-name state) state)))
(if-let (configmap (kubernetes-state-lookup-configmap configmap-name state))
(select-window
(display-buffer
(kubernetes-yaml-make-buffer kubernetes-display-configmap-buffer-name configmap)))
(error "Unknown configmap: %s" configmap-name)))
(provide 'kubernetes-configmaps)
;;; kubernetes-configmaps.el ends here

View file

@ -1,83 +0,0 @@
;;; kubernetes-contexts.el --- Rendering for Kubernetes contexts -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-kubectl)
(require 'kubernetes-modes)
(require 'kubernetes-process)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-yaml)
;; Component
(defun kubernetes-contexts--render-current-context (context current-namespace)
(-let* (((&alist 'name name
'context (&alist 'cluster cluster-name
'namespace context-namespace))
context)
(context-name (propertize name 'face 'kubernetes-context-name))
(namespace-in-use (or current-namespace context-namespace "default")))
`((nav-prop :display-config
(heading (key-value 12 "Context" ,context-name))
(key-value 12 "Cluster" ,cluster-name))
(section (namespace nil)
(nav-prop (:namespace-name ,namespace-in-use)
(key-value 12 "Namespace" ,(propertize namespace-in-use 'face 'kubernetes-namespace)))))))
(defun kubernetes-contexts--render-namespace-only (current-namespace)
(let ((none (propertize "<none>" 'face 'magit-dimmed)))
`((heading (nav-prop :display-config (key-value 12 "Context" ,none)))
(section (namespace nil)
(nav-prop (:namespace-name ,current-namespace)
(key-value 12 "Namespace" ,(propertize current-namespace 'face 'kubernetes-namespace)))))))
(defun kubernetes-contexts--render-fetching ()
(let ((fetching (propertize "Fetching..." 'face 'kubernetes-progress-indicator)))
`(heading (key-value 12 "Context" ,fetching))))
(defun kubernetes-contexts-render (state)
(let ((current-namespace (kubernetes-state-current-namespace state))
(current-context (kubernetes-state-current-context state)))
`(section (context-container nil)
(section (context nil)
,(cond
(current-context
(kubernetes-contexts--render-current-context current-context current-namespace))
(current-namespace
(kubernetes-contexts--render-namespace-only current-namespace))
(t
(kubernetes-contexts--render-fetching)))
(padding)))))
;; Requests and state management
(kubernetes-state-define-refreshers config kubernetes-kubectl-config-view
"config view -o json")
(defalias 'kubernetes-contexts-refresh-now 'kubernetes-config-refresh-now)
(defalias 'kubernetes-contexts-refresh 'kubernetes-config-refresh-now)
(defalias 'kubernetes-state-contexts 'kubernetes-state-config)
(defalias 'kubernetes-state-update-contexts 'kubernetes-state-update-config)
;; Displaying config.
;;;###autoload
(defun kubernetes-display-config (config)
"Display information for CONFIG in a new window."
(interactive (list (kubernetes-kubectl-await-on-async kubernetes-props (kubernetes-state) #'kubernetes-kubectl-config-view)))
(select-window
(display-buffer
(kubernetes-yaml-make-buffer kubernetes-display-config-buffer-name config))))
(provide 'kubernetes-contexts)
;;; kubernetes-contexts.el ends here

View file

@ -1,195 +0,0 @@
;;; kubernetes-deployments.el --- Rendering for Kubernetes deployments. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-kubectl)
(require 'kubernetes-modes)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-vars)
(require 'kubernetes-yaml)
;;;; Components
(defconst kubernetes-deployments--column-heading
["%-45s %10s %10s %10s %6s" "Name Replicas UpToDate Available Age"])
(kubernetes-ast-define-component deployment-detail (deployment)
(-let [(&alist 'metadata (&alist 'namespace ns 'creationTimestamp time)
'spec (&alist 'selector (&alist 'matchLabels
(&alist 'name selector-name
'component component-name)
'matchExpressions match-expressions)))
deployment]
`(,(when selector-name
`(section (selector nil)
(nav-prop (:selector ,selector-name)
(key-value 12 "Selector" ,(propertize selector-name 'face 'kubernetes-selector)))))
,(when component-name
`(section (component nil)
(nav-prop (:component ,component-name)
(key-value 12 "Component" ,(propertize component-name 'face 'kubernetes-component)))))
,(when match-expressions
`(section (expressions nil)
(heading "Match Expressions")
(indent ,(kubernetes-yaml-render match-expressions))))
(section (namespace nil)
(nav-prop (:namespace-name ,ns)
(key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace))))
(key-value 12 "Created" ,time))))
(kubernetes-ast-define-component deployment-line (state deployment)
(-let* ((current-time (kubernetes-state-current-time state))
(pending-deletion (kubernetes-state-deployments-pending-deletion state))
(marked-deployments (kubernetes-state-marked-deployments state))
((&alist 'metadata (&alist 'name name 'creationTimestamp created-time)
'spec (&alist 'replicas desired)
'status (&alist 'replicas current
'availableReplicas available
'updatedReplicas up-to-date))
deployment)
(current (or current 0))
(desired (or desired 0))
(available (or available 0))
(up-to-date (or up-to-date 0))
([fmt] kubernetes-deployments--column-heading)
(list-fmt (split-string fmt))
(line `(line ,(concat
;; Name
(format (pop list-fmt) (kubernetes-utils-ellipsize name 45))
" "
;; Replicas (current/desired)
(let ((next (pop list-fmt))
(str (format "%s/%s" current desired)))
(cond
((zerop desired)
(format next str))
((zerop current)
(propertize (format next str) 'face 'warning))
((/= current desired)
(format next str))
(t
(propertize (format next str) 'face 'magit-dimmed))))
" "
;; Up-to-date
(let ((next (pop list-fmt)))
(cond
((zerop desired)
(format next up-to-date))
((zerop up-to-date)
(propertize (format next up-to-date) 'face 'warning))
(t
(propertize (format next up-to-date) 'face 'magit-dimmed))))
" "
;; Available
(let ((next (pop list-fmt)))
(cond
((zerop desired)
(format next available))
((zerop available)
(propertize (format next available) 'face 'warning))
(t
(propertize (format next available) 'face 'magit-dimmed))))
" "
;; Age
(let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
(propertize (format (pop list-fmt) (kubernetes-utils-time-diff-string start current-time))
'face 'magit-dimmed))))))
`(nav-prop (:deployment-name ,name)
(copy-prop ,name
,(cond
((member name pending-deletion)
`(propertize (face kubernetes-pending-deletion) ,line))
((member name marked-deployments)
`(mark-for-delete ,line))
((zerop desired)
`(propertize (face magit-dimmed) ,line))
(t
line))))))
(kubernetes-ast-define-component deployment (state deployment)
`(section (,(intern (kubernetes-state-resource-name deployment)) t)
(heading (deployment-line ,state ,deployment))
(section (details nil)
(indent
(deployment-detail ,deployment)
(padding)))))
(kubernetes-ast-define-component deployments-list (state &optional hidden)
(-let (((state-set-p &as &alist 'items deployments) (kubernetes-state-deployments state))
([fmt labels] kubernetes-deployments--column-heading))
`(section (deployments-container ,hidden)
(header-with-count "Deployments" ,deployments)
(indent
(columnar-loading-container ,deployments
,(propertize
(apply #'format fmt (split-string labels))
'face
'magit-section-heading)
,(--map `(deployment ,state ,it) deployments)))
(padding))))
;; Requests and state management
(kubernetes-state-define-refreshers deployments)
(defun kubernetes-deployments-delete-marked (state)
(let ((names (kubernetes-state-marked-deployments state)))
(dolist (name names)
(kubernetes-state-delete-deployment name)
(kubernetes-kubectl-delete-deployment kubernetes-props state name
(lambda (_)
(message "Deleting deployment %s succeeded." name))
(lambda (_)
(message "Deleting deployment %s failed" name)
(kubernetes-state-mark-deployment name))))
(kubernetes-state-trigger-redraw)))
;;;; Displaying deployments
(defun kubernetes-deployments--read-name (state)
"Read a deployment name from the user.
STATE is the current application state.
Update the deployment state if it not set yet."
(-let* (((&alist 'items deployments)
(or (kubernetes-state-deployments state)
(progn
(message "Getting deployments...")
(let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-deployments)))
(kubernetes-state-update-deployments response)
response))))
(deployments (append deployments nil))
(names (-map #'kubernetes-state-resource-name deployments)))
(completing-read "Deployment: " names nil t)))
;;###autoload
(defun kubernetes-display-deployment (deployment-name state)
"Display information for a deployment in a new window.
STATE is the current application state.
DEPLOYMENT-NAME is the name of the deployment to display."
(interactive (let ((state (kubernetes-state)))
(list (kubernetes-deployments--read-name state) state)))
(if-let (deployment (kubernetes-state-lookup-deployment deployment-name state))
(select-window
(display-buffer
(kubernetes-yaml-make-buffer kubernetes-display-deployment-buffer-name deployment)))
(error "Unknown deployment: %s" deployment-name)))
(provide 'kubernetes-deployments)
;;; kubernetes-deployments.el ends here

View file

@ -1,31 +0,0 @@
;;; kubernetes-errors.el --- Rendering for Kubernetes errors -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'subr-x)
(require 'kubernetes-state)
(defun kubernetes-errors-render (state)
(-when-let* (((&alist 'message message 'command command) (kubernetes-state-last-error state))
(message-paragraph
(with-temp-buffer
(insert message)
(fill-region (point-min) (point-max))
(indent-region (point-min) (point-max) 2)
(string-trim-right (buffer-string)))))
`(section (error nil)
(heading (propertize (face font-lock-warning-face) "kubectl command failed"))
(padding)
(section (message nil)
(copy-prop ,message (line ,message-paragraph))
(padding))
(section (command nil)
(key-value 10 "Command" ,command)
(padding)))))
(provide 'kubernetes-errors)
;;; kubernetes-errors.el ends here

View file

@ -1,138 +0,0 @@
;;; kubernetes-ingress.el --- Rendering routines for Kubernetes ingress. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-ast)
(require 'kubernetes-loading-container)
(require 'kubernetes-modes)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-yaml)
;; Components
(defconst kubernetes-ingress--column-heading
(propertize (format "%-45s %-25s %20s %10s" "Name" "Hosts" "Address" "Age")
'face 'magit-section-heading))
(kubernetes-ast-define-component ingress-detail (ingress)
(-let [(&alist 'metadata (&alist 'namespace ns 'creationTimestamp time)) ingress]
`((section (namespace nil)
(nav-prop (:namespace-name ,ns)
(key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace))))
(key-value 12 "Created" ,time))))
(kubernetes-ast-define-component ingress-line (state ingress)
(-let* ((current-time (kubernetes-state-current-time state))
(pending-deletion (kubernetes-state-ingress-pending-deletion state))
(marked-ingress (kubernetes-state-marked-ingress state))
((&alist 'metadata (&alist 'name name 'creationTimestamp created-time)
'spec (&alist 'rules ingress-rules)
'status (&alist 'loadBalancer (&alist 'ingress ingress-lb-list)))
ingress)
(line `(line ,(concat
;; Name
(format "%-45s " (kubernetes-utils-ellipsize name 45))
;; Hosts
(format "%-25s " (--mapcat (alist-get 'host it) ingress-rules))
;; Address
(format "%20s "
(mapconcat
'identity
(mapcar
(lambda (i) (format "%s" (alist-get 'ip i )))
ingress-lb-list)
", "))
;; Age
(let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
(propertize (format "%10s" (kubernetes-utils-time-diff-string start current-time))
'face 'magit-dimmed))))))
`(nav-prop (:ingress-name ,name)
(copy-prop ,name
,(cond
((member name pending-deletion)
`(propertize (face kubernetes-pending-deletion) ,line))
((member name marked-ingress)
`(mark-for-delete ,line))
(t
line))))))
(kubernetes-ast-define-component ingress (state ingress)
`(section (,(intern (kubernetes-state-resource-name ingress)) t)
(heading (ingress-line ,state ,ingress))
(section (details nil)
(indent
(ingress-detail ,ingress)
(padding)))))
(kubernetes-ast-define-component ingress-list (state &optional hidden)
(-let [(&alist 'items ingress) (kubernetes-state-ingress state)]
`(section (ingress-container ,hidden)
(header-with-count "Ingress" ,ingress)
(indent
(columnar-loading-container ,ingress ,kubernetes-ingress--column-heading
,(--map `(ingress ,state ,it) ingress)))
(padding))))
;; Requests and state management
(kubernetes-state-define-refreshers ingress)
(defun kubernetes-ingress-delete-marked (state)
(let ((names (kubernetes-state-marked-ingress state)))
(dolist (name names)
(kubernetes-state-delete-ingress name)
(kubernetes-kubectl-delete-ingress kubernetes-props state name
(lambda (_)
(message "Deleting ingress %s succeeded." name))
(lambda (_)
(message "Deleting ingress %s failed" name)
(kubernetes-state-mark-ingress name))))
(kubernetes-state-trigger-redraw)))
;; Displaying ingress
(defun kubernetes-ingress--read-name (state)
"Read a ingress name from the user.
STATE is the current application state.
Update the ingress state if it not set yet."
(-let* (((&alist 'items ingress)
(or (kubernetes-state-ingress state)
(progn
(message "Getting ingress...")
(let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-ingress)))
(kubernetes-state-update-ingress response)
response))))
(ingress (append ingress nil))
(names (-map #'kubernetes-state-resource-name ingress)))
(completing-read "Ingress: " names nil t)))
;;;###autoload
(defun kubernetes-display-ingress (ingress-name state)
"Display information for a ingress in a new window.
STATE is the current application state.
INGRESS-NAME is the name of the ingress to display."
(interactive (let ((state (kubernetes-state)))
(list (kubernetes-ingress--read-name state) state)))
(if-let (ingress (kubernetes-state-lookup-ingress ingress-name state))
(select-window
(display-buffer
(kubernetes-yaml-make-buffer kubernetes-display-ingress-buffer-name ingress)))
(error "Unknown ingress: %s" ingress-name)))
(provide 'kubernetes-ingress)
;;; kubernetes-ingress.el ends here

View file

@ -1,180 +0,0 @@
;;; kubernetes-jobs.el --- Rendering for Kubernetes jobs. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-ast)
(require 'kubernetes-kubectl)
(require 'kubernetes-modes)
(require 'kubernetes-pod-line)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-vars)
(require 'kubernetes-yaml)
;; Components
(defconst kubernetes-jobs--column-heading
["%-45s %10s %6s" "Name Successful Age"])
(kubernetes-ast-define-component job-detail (state pod job)
(-let* (((&alist 'metadata (&alist 'namespace ns
'creationTimestamp time)
'spec (&alist 'template
(&alist 'spec (&alist 'restartPolicy restart-policy)))
'status (&alist
'startTime start-time
'completionTime completion-time))
job)
((&alist 'items pods) (kubernetes-state-pods state)))
`((section (namespace nil)
(nav-prop (:namespace-name ,ns)
(key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace))))
,(when restart-policy
`(key-value 12 "RestartPolicy" ,restart-policy))
(padding)
(key-value 12 "Created" ,time)
,(when start-time
`(key-value 12 "Started" ,start-time))
,(when completion-time
`(key-value 12 "Completed" ,completion-time))
(padding)
(section (pod nil)
(heading "Pod")
(indent
(membership-loading-container ,pod ,pods
(pod-line ,state ,pod)
(padding)))))))
(kubernetes-ast-define-component job-line (state pod job)
(-let* ((current-time (kubernetes-state-current-time state))
(pending-deletion (kubernetes-state-jobs-pending-deletion state))
(marked-jobs (kubernetes-state-marked-jobs state))
((&alist 'metadata (&alist 'name name 'creationTimestamp created-time)
'status (&alist 'succeeded successful
'completionTime completion-time))
job)
(successful (or successful 0))
([fmt] kubernetes-jobs--column-heading)
(list-fmt (split-string fmt))
(line (concat
;; Name
(let ((name-str (format (pop list-fmt) (kubernetes-utils-ellipsize name 45))))
(cond
((and completion-time (< 0 successful))
(propertize name-str 'face 'magit-dimmed))
((not (kubernetes-pod-line-ok-p pod))
(propertize name-str 'face 'warning))
(t
name-str)))
" "
;; Successful
(propertize (format (pop list-fmt) successful) 'face 'magit-dimmed)
" "
;; Age
(let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
(propertize (format (pop list-fmt) (kubernetes-utils-time-diff-string start current-time))
'face 'magit-dimmed)))))
`(nav-prop (:job-name ,name)
(copy-prop ,name
(line ,(cond
((member name pending-deletion)
`(propertize (face kubernetes-pending-deletion) ,line))
((member name marked-jobs)
`(mark-for-delete ,line))
(t
line)))))))
(defun kubernetes-jobs--lookup-pod-for-job (job state)
(-let* (((&alist 'metadata (&alist 'labels (&alist 'job-name job-name))) job)
((&alist 'items items) (kubernetes-state-pods state)))
(seq-find (lambda (pod)
(let ((pod-name (kubernetes-state-resource-name pod)))
(string-prefix-p job-name pod-name)))
items)))
(kubernetes-ast-define-component job (state job)
(let ((pod (kubernetes-jobs--lookup-pod-for-job job state)))
`(section (,(intern (kubernetes-state-resource-name job)) t)
(heading (job-line ,state ,pod ,job))
(section (details nil)
(indent
(job-detail ,state ,pod ,job))))))
(kubernetes-ast-define-component jobs-list (state &optional hidden)
(-let (((state-set-p &as &alist 'items jobs) (kubernetes-state-jobs state))
([fmt labels] kubernetes-jobs--column-heading))
`(section (jobs-container ,hidden)
(header-with-count "Jobs" ,jobs)
(indent
(columnar-loading-container ,jobs
,(propertize
(apply #'format fmt (split-string labels))
'face
'magit-section-heading)
,(--map `(job ,state ,it) jobs)))
(padding))))
;; Requests and state management
(kubernetes-state-define-refreshers jobs)
(defun kubernetes-jobs-delete-marked (state)
(let ((names (kubernetes-state-marked-jobs state)))
(dolist (name names)
(kubernetes-state-delete-job name)
(kubernetes-kubectl-delete-job kubernetes-props state name
(lambda (_)
(message "Deleting job %s succeeded." name))
(lambda (_)
(message "Deleting job %s failed" name)
(kubernetes-state-mark-job name))))
(kubernetes-state-trigger-redraw)))
;; Displaying jobs
(defun kubernetes-jobs--read-name (state)
"Read a job name from the user.
STATE is the current application state.
Update the job state if it not set yet."
(-let* (((&alist 'items jobs)
(or (kubernetes-state-jobs state)
(progn
(message "Getting jobs...")
(let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-jobs)))
(kubernetes-state-update-jobs response)
response))))
(jobs (append jobs nil))
(names (-map #'kubernetes-state-resource-name jobs)))
(completing-read "Job: " names nil t)))
;;;###autoload
(defun kubernetes-display-job (job-name state)
"Display information for a job in a new window.
STATE is the current application state.
JOB-NAME is the name of the job to display."
(interactive (let ((state (kubernetes-state)))
(list (kubernetes-jobs--read-name state) state)))
(if-let (job (kubernetes-state-lookup-job job-name state))
(select-window
(display-buffer
(kubernetes-yaml-make-buffer kubernetes-display-job-buffer-name job)))
(error "Unknown job: %s" job-name)))
(provide 'kubernetes-jobs)
;;; kubernetes-jobs.el ends here

View file

@ -1,524 +0,0 @@
;;; kubernetes-kubectl.el --- Low-level kubectl integration routines. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-process)
(require 'kubernetes-props)
(require 'kubernetes-state)
(require 'kubernetes-vars)
(autoload 'json-read-from-string "json")
(autoload 'kubernetes-utils-up-to-existing-dir "kubernetes-utils")
(defun kubernetes-kubectl--default-error-handler (props status)
(unless (kubernetes-props-overview-buffer-selected-p props)
(let* ((last-error (kubernetes-props-get-last-error props))
(last-error (concat
(or (when (listp last-error)
(alist-get 'command last-error))
"undefined command")
": "
(or (when (listp last-error)
(alist-get 'message last-error))
"undefined error")))
(process-killed-manually (string-match-p (rx bol (* space) "killed:" (* space) "9" (* space) eol) status)))
(unless process-killed-manually
(kubernetes-props-message props (string-trim-right last-error))))))
(defun kubernetes-kubectl--flags-from-state (state)
(append (when-let (ns (kubernetes-state-current-namespace state))
(list (format "--namespace=%s" ns)))
(kubernetes-state-kubectl-flags state)))
(defun kubernetes-kubectl (props state args on-success &optional on-error cleanup-cb)
"Run kubectl with ARGS.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the current application state, used to apply additional
global flags to kubectl.
ON-SUCCESS is a function of one argument, called with the process' buffer.
Optional ON-ERROR is a function of two arguments, called with the
process' stderr buffer. If omitted, it defaults to
`kubernetes-kubectl--default-error-handler', which logs an error
if the process exited unexpectedly.
Optional CLEANUP-CB is a function of no arguments that is always
called after the other callbacks. It can be used for releasing
resources.
After callbacks are executed, the process and its buffer will be killed.
Returns the process object for this execution of kubectl."
(let* ((buf (generate-new-buffer " kubectl"))
(err-buf (generate-new-buffer " kubectl-err"))
(command (append (list kubernetes-kubectl-executable) args (kubernetes-kubectl--flags-from-state state)))
;; `default-directory' must exist, otherwise `make-process' raises an
;; error.
(default-directory (kubernetes-utils-up-to-existing-dir default-directory))
(proc (make-process
:name "kubectl"
:buffer buf
:stderr err-buf
:command command
:noquery t
:sentinel
(lambda (proc status)
(unwind-protect
(let ((exit-code (process-exit-status proc)))
(cond
((zerop exit-code)
(funcall on-success buf))
(t
(let ((err-message (with-current-buffer err-buf (buffer-string))))
(unless (= 9 exit-code)
(kubernetes-props-update-last-error props err-message (string-join command " ") (current-time))))
(cond (on-error
(funcall on-error err-buf))
(t
(kubernetes-kubectl--default-error-handler props status))))))
(when cleanup-cb
(funcall cleanup-cb))
(kubernetes-process-kill-quietly proc))))))
;; Clean up stderr buffer when stdout buffer is killed.
(with-current-buffer buf
(add-hook 'kill-buffer-hook (lambda ()
(let ((kill-buffer-query-functions nil))
(ignore-errors (kill-buffer err-buf))))
nil t))
proc))
(defun kubernetes-kubectl-get-pods (props state cb &optional cleanup-cb)
"Get all pods and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "pods" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-nodes (props state cb &optional cleanup-cb)
"Get all nodes and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "nodes" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-configmaps (props state cb &optional cleanup-cb)
"Get all configmaps and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "configmaps" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-deployments (props state cb &optional cleanup-cb)
"Get all deployments and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "deployments" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-statefulsets (props state cb &optional cleanup-cb)
"Get all statefulsets and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "statefulsets" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-ingress (props state cb &optional cleanup-cb)
"Get all ingress and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "ingress" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-jobs (props state cb &optional cleanup-cb)
"Get all jobs and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "jobs" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-secrets (props state cb &optional cleanup-cb)
"Get all secrets and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "secrets" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-get-services (props state cb &optional cleanup-cb)
"Get all services and execute callback CB with the parsed JSON.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "services" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-config-view (props state cb &optional cleanup-cb)
"Get the current configuration and pass it to CB.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props
state
'("config" "view" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-config-use-context (props state context-name cb)
"Change the current kubernetes context to CONTEXT-NAME, a string.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CB is a function taking the name of the context that was switched to."
(kubernetes-kubectl props
state
(list "config" "use-context" context-name)
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "Switched to context \"" (group (+? nonl)) "\"." (* space) eol)
(buffer-string))
(funcall cb (match-string 1 (buffer-string)))))))
(defun kubernetes-kubectl-get-namespaces (props state cb &optional cleanup-cb)
"Get namespaces for the current cluster and pass the parsed response to CB.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
CLEANUP-CB is a function taking no arguments used to release any resources."
(kubernetes-kubectl props state '("get" "namespaces" "-o" "json")
(lambda (buf)
(let ((json (with-current-buffer buf
(json-read-from-string (buffer-string)))))
(funcall cb json)))
nil
cleanup-cb))
(defun kubernetes-kubectl-delete-pod (props state pod-name cb &optional error-cb)
"Delete pod with POD-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "pod" pod-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "pod/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-configmap (props state configmap-name cb &optional error-cb)
"Delete CONFIGMAP-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "configmap" configmap-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "configmap/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-ingress (props state ingress-name cb &optional error-cb)
"Delete INGRESS-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "ingress" ingress-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "ingress/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-secret (props state secret-name cb &optional error-cb)
"Delete SECRET-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "secret" secret-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "secret/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-describe-pod (props state pod-name cb)
"Describe pod with POD-NAME, then execute CB with the string response.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state."
(kubernetes-kubectl props state (list "describe" "pod" pod-name)
(lambda (buf)
(let ((s (with-current-buffer buf (buffer-string))))
(funcall cb s)))))
(defun kubernetes-kubectl-delete-service (props state service-name cb &optional error-cb)
"Delete SERVICE-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "service" service-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "service/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-deployment (props state deployment-name cb &optional error-cb)
"Delete DEPLOYMENT-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "deployment" deployment-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "deployment/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-statefulset (props state statefulset-name cb &optional error-cb)
"Delete STATEFULSET-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "statefulset" statefulset-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "statefulset/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-delete-job (props state job-name cb &optional error-cb)
"Delete JOB-NAME, then execute CB with the response buffer.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
ERROR-CB is called if an error occurred."
(kubernetes-kubectl props state (list "delete" "job" job-name "-o" "name")
(lambda (buf)
(with-current-buffer buf
(string-match (rx bol "job/" (group (+ nonl))) (buffer-string))
(funcall cb (match-string 1 (buffer-string)))))
error-cb))
(defun kubernetes-kubectl-await (command &rest callbacks)
"Apply COMMAND to list of CALLBACKS where first callback is assumed on-success.
If no callbacks called within `kubernetes-kubectl-timeout-seconds', give up,
possibly orphaning a process.
Return result of first callback if success, nil otherwise."
(let* (result
complete
sentinelized
(sentinel (lambda (&rest _args) (setq complete t))))
(mapc (lambda (f)
(when (functionp f)
(add-function :before (var f) sentinel))
(push f sentinelized))
callbacks)
(setf sentinelized (nreverse sentinelized))
(when (functionp (car sentinelized))
(add-function :around (car sentinelized)
(lambda (f &rest args)
(setq result (apply f args)))))
(cl-loop initially do (apply command sentinelized)
with ms = 500
with count = (max 1 (truncate
(/ (* 1000 kubernetes-kubectl-timeout-seconds)
ms)))
repeat count
until complete
do (sleep-for 0 ms)
finally return result)))
(defmacro kubernetes-kubectl-await-command (resource for-items)
(declare (indent defun))
"Await kubectl updating state's RESOURCE and return result of calling
FOR-ITEMS on updated RESOURCEs."
`(kubernetes-kubectl-await
(apply-partially #'kubernetes-kubectl
kubernetes-props
(kubernetes-state)
(split-string ,(format "get %s -o json" (symbol-name resource))))
(lambda (buf)
(with-current-buffer buf
(,(intern (concat "kubernetes-state-update-" (symbol-name resource)))
(json-read-from-string (buffer-string)))
(-let* (((&alist 'items)
(,(intern (concat "kubernetes-state-" (symbol-name resource)))
(kubernetes-state))))
(seq-map ,for-items items))))
nil
#'ignore))
(defun kubernetes-kubectl-await-on-async (props state fn)
"Turn an async function requiring a callback into a synchronous one.
PROPS is an alist of functions to inject. It should normally be passed
`kubernetes-props'.
STATE is the application state.
Transforms a function of type:
FN : (props, state, a -> b) -> process
to a function of the type:
FN' : () -> a"
(let* (complete result)
(funcall fn props state (lambda (response)
(setq complete t)
(setq result response)))
(while (not complete)
(sleep-for 0.001))
result))
(provide 'kubernetes-kubectl)
;;; kubernetes-kubectl.el ends here

View file

@ -1,85 +0,0 @@
;;; kubernetes-labels.el --- Utils for displaying resources with a particular label. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 'kubernetes-ast)
(require 'kubernetes-commands)
(require 'kubernetes-loading-container)
(require 'kubernetes-pods)
(require 'kubernetes-state)
(require 'kubernetes-utils)
(require 'kubernetes-vars)
;; Component
(kubernetes-ast-define-component labelled-pods-list (state)
(-let* ((query (kubernetes-state-label-query state))
((&alist 'items pods) (kubernetes-state-pods state))
(matches (nreverse (seq-reduce
(lambda (acc pod)
(if (equal query (kubernetes-state-resource-label pod))
(cons `(pod ,state ,pod) acc)
acc))
pods
nil)))
([fmt labels] kubernetes-pods--column-heading))
`(section (root nil)
(section (query-header nil)
(key-value 10 "Label" ,(propertize query 'face 'kubernetes-selector))
(padding))
(indent
(columnar-loading-container ,pods
,(propertize
(apply #'format fmt (split-string labels))
'face
'magit-section-heading)
,matches)))))
;; Commands
(defun kubernetes-labels--redraw-buffer ()
"Redraws the labels query buffer using the current state."
(when-let (buf (get-buffer kubernetes-label-query-buffer-name))
(with-current-buffer buf
;; Only redraw the buffer if it is in the selected window.
(when (equal (get-buffer-window buf)
(selected-window))
(kubernetes-utils--save-window-state
(let ((inhibit-read-only t))
(erase-buffer)
(kubernetes-ast-eval `(labelled-pods-list ,(kubernetes-state)))))
;; Force the section at point to highlight.
(magit-section-update-highlight)))))
(defun kubernetes-labels--initialize-buffer ()
"Called the first time the labels buffer is opened to set up the buffer."
(let ((buf (get-buffer-create kubernetes-label-query-buffer-name)))
(with-current-buffer buf
(kubernetes-mode)
(kubernetes-timers-initialize-timers)
(add-hook 'kubernetes-redraw-hook #'kubernetes-labels--redraw-buffer)
(add-hook 'kill-buffer-hook (kubernetes-utils-make-cleanup-fn buf) nil t))
buf))
;;;###autoload
(defun kubernetes-show-pods-for-label (label-query)
"Display a buffer for pods matching a label.
LABEL-QUERY is a string used to match pods."
(interactive
(-let* (((&alist 'items pods) (kubernetes-state-pods (kubernetes-state)))
(labels (-non-nil (-uniq (seq-map #'kubernetes-state-resource-label pods)))))
(list (completing-read "Label: " labels))))
(kubernetes-state-update-label-query label-query)
(with-current-buffer (kubernetes-labels--initialize-buffer)
(kubernetes-commands-display-buffer (current-buffer))
(kubernetes-labels--redraw-buffer)))
(provide 'kubernetes-labels)
;;; kubernetes-labels.el ends here

View file

@ -1,78 +0,0 @@
;;; kubernetes-loading-container.el --- Component for resources that are loaded asynchronously. -*- lexical-binding: t; -*-
;;; Commentary:
;; A loading container displays placeholder text while a resource is loading in
;; the background.
;;
;; Other components build on this functionality to render differently depending
;; on the loaded state of some resource.
;;; Code:
(require 'kubernetes-ast)
(kubernetes-ast-define-component membership-loading-discriminator (elem vector &key on-loading on-found on-not-found)
(cond
((null vector)
on-loading)
((and vector (seq-contains vector elem))
on-found)
(t
on-not-found)))
(kubernetes-ast-define-component membership-loading-container (elem vector &rest loaded-content)
`(membership-loading-discriminator
,elem ,vector
:on-loading
(line (propertize (face kubernetes-progress-indicator) (line "Fetching...")))
:on-found
,loaded-content
:on-not-found
(line (propertize (face kubernetes-progress-indicator) "Not found."))))
(kubernetes-ast-define-component emptiness-loading-discriminator (vector &key on-loading on-empty on-populated)
(cond
((and (vectorp vector) (equal 0 (length vector)))
on-empty)
(vector
on-populated)
(t
on-loading)))
(kubernetes-ast-define-component columnar-loading-container (resource-vector column-header &rest loaded-content)
`(emptiness-loading-discriminator
,resource-vector
:on-loading
(,@(when column-header
(list (cons 'line (list column-header))))
(propertize (face kubernetes-progress-indicator)
(line "Fetching...")))
:on-empty
(propertize (face magit-dimmed) (line "None."))
:on-populated
(,@(when column-header
(list (cons 'line (list column-header))))
,@loaded-content)))
(kubernetes-ast-define-component header-with-count (header resource-vector)
(let ((header (propertize header 'face 'magit-header-line)))
`(heading
(emptiness-loading-discriminator
,resource-vector
:on-loading
,header
:on-empty
,(concat header " (0)")
:on-populated
,(concat header (format " (%s)" (length resource-vector)))))))
(provide 'kubernetes-loading-container)
;;; kubernetes-loading-container.el ends here

View file

@ -1,132 +0,0 @@
;;; kubernetes-logs.el --- Utilities for working with log buffers. -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'subr-x)
(require 'kubernetes-modes)
(require 'kubernetes-popups)
(require 'kubernetes-utils)
(autoload 'json-pretty-print-buffer "json")
(require 'kubernetes-vars)
(defun kubernetes-logs--log-line-buffer-for-string (s)
(let ((propertized (with-temp-buffer
(insert s)
(goto-char (point-min))
(when (equal (char-after) ?\{)
(json-pretty-print-buffer)
(funcall kubernetes-json-mode)
(font-lock-ensure))
(buffer-string))))
(with-current-buffer (get-buffer-create kubernetes-log-line-buffer-name)
(kubernetes-log-line-mode)
(let ((inhibit-read-only t))
(erase-buffer)
(insert propertized)
(goto-char (point-min)))
(current-buffer))))
;;;###autoload
(defun kubernetes-logs-inspect-line (pos)
"Show detail for the log line at POS."
(interactive "d")
(display-buffer (kubernetes-logs--log-line-buffer-for-string
(save-excursion
(goto-char pos)
(buffer-substring (line-beginning-position) (line-end-position))))))
;;;###autoload
(defun kubernetes-logs-previous-line ()
"Move backward and inspect the line at point."
(interactive)
(with-current-buffer kubernetes-logs-buffer-name
(forward-line -1)
(when (get-buffer kubernetes-log-line-buffer-name)
(kubernetes-logs-inspect-line (point)))))
;;;###autoload
(defun kubernetes-logs-forward-line ()
"Move forward and inspect the line at point."
(interactive)
(with-current-buffer kubernetes-logs-buffer-name
(forward-line 1)
(when (get-buffer kubernetes-log-line-buffer-name)
(kubernetes-logs-inspect-line (point)))))
;;;###autoload
(defun kubernetes-logs-follow (pod-name args state)
"Open a streaming logs buffer for a pod.
POD-NAME is the name of the pod to log.
ARGS are additional args to pass to kubectl.
STATE is the current application state."
(interactive
(let ((state (kubernetes-state)))
(list (or (kubernetes-utils-maybe-pod-name-at-point)
(kubernetes-utils-read-pod-name state))
(kubernetes-logs-arguments)
state)))
(kubernetes-logs-fetch-all pod-name (cons "-f" args) state))
;;;###autoload
(defun kubernetes-logs-fetch-all (pod-name args state)
"Open a streaming logs buffer for POD.
POD-NAME is the name of the pod to log.
ARGS are additional args to pass to kubectl.
STATE is the current application state"
(interactive
(let ((state (kubernetes-state)))
(list (or (kubernetes-utils-maybe-pod-name-at-point) (kubernetes-utils-read-pod-name state))
(kubernetes-logs-arguments)
state)))
(let ((args (append (list "logs") args (list pod-name) (kubernetes-kubectl--flags-from-state (kubernetes-state))
(when-let (ns (kubernetes-state-current-namespace state))
(list (format "--namespace=%s" ns))))))
(with-current-buffer (kubernetes-utils-process-buffer-start kubernetes-logs-buffer-name #'kubernetes-logs-mode kubernetes-kubectl-executable args)
(select-window (display-buffer (current-buffer))))))
;;;###autoload
(defvar kubernetes-logs-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "n") #'kubernetes-logs-forward-line)
(define-key keymap (kbd "p") #'kubernetes-logs-previous-line)
(define-key keymap (kbd "RET") #'kubernetes-logs-inspect-line)
keymap)
"Keymap for `kubernetes-logs-mode'.")
;;;###autoload
(define-derived-mode kubernetes-logs-mode kubernetes-mode "Kubernetes Logs"
"Mode for displaying and inspecting Kubernetes logs.
\\<kubernetes-logs-mode-map>\
Type \\[kubernetes-logs-inspect-line] to open the line at point in a new buffer.
\\{kubernetes-logs-mode-map}")
;;;###autoload
(defvar kubernetes-log-line-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "n") #'kubernetes-logs-forward-line)
(define-key keymap (kbd "p") #'kubernetes-logs-previous-line)
keymap)
"Keymap for `kubernetes-log-line-mode'.")
;;;###autoload
(define-derived-mode kubernetes-log-line-mode kubernetes-mode "Log Line"
"Mode for inspecting Kubernetes log lines.
\\{kubernetes-log-line-mode-map}")
(provide 'kubernetes-logs)
;;; kubernetes-logs.el ends here

Some files were not shown because too many files have changed in this diff Show more