Commit a34f57247060
Changed files (58)
.emacs.d
elpa
kubernetes-20170523.1517
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-ast.el
@@ -0,0 +1,313 @@
+;;; 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 (magit-section-content magit-insert-section--current) (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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-ast.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-autoloads.el
@@ -0,0 +1,356 @@
+;;; 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-commands" "kubernetes-commands.el"
+;;;;;; (22902 775 539819 510000))
+;;; 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.
+
+Inspecs 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-configmaps" "kubernetes-configmaps.el"
+;;;;;; (22902 775 664810 938000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-contexts" "kubernetes-contexts.el"
+;;;;;; (22902 775 608814 778000))
+;;; Generated autoloads from kubernetes-contexts.el
+
+(autoload 'kubernetes-display-config "kubernetes-contexts" "\
+Display information for CONFIG in a new window.
+
+\(fn CONFIG)" t nil)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-deployments" "kubernetes-deployments.el"
+;;;;;; (22902 775 696808 743000))
+;;; Generated autoloads from kubernetes-deployments.el
+
+(autoload 'kubernetes-display-deployment "kubernetes-deployments" "\
+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.
+
+\(fn DEPLOYMENT-NAME STATE)" t nil)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-jobs" "kubernetes-jobs.el" (22902
+;;;;;; 775 592815 875000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-labels" "kubernetes-labels.el"
+;;;;;; (22902 775 715807 441000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-logs" "kubernetes-logs.el" (22902
+;;;;;; 775 580816 698000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-modes" "kubernetes-modes.el" (22902
+;;;;;; 775 702808 332000))
+;;; 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"
+;;;;;; (22902 775 614814 367000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-overview" "kubernetes-overview.el"
+;;;;;; (22902 775 620813 955000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-pods" "kubernetes-pods.el" (22902
+;;;;;; 775 674810 252000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-secrets" "kubernetes-secrets.el"
+;;;;;; (22902 775 669810 595000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil "kubernetes-services" "kubernetes-services.el"
+;;;;;; (22902 775 690809 155000))
+;;; 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)
+
+;;;***
+
+;;;### (autoloads nil nil ("kubernetes-ast.el" "kubernetes-errors.el"
+;;;;;; "kubernetes-kubectl.el" "kubernetes-loading-container.el"
+;;;;;; "kubernetes-pkg.el" "kubernetes-pod-line.el" "kubernetes-popups.el"
+;;;;;; "kubernetes-process.el" "kubernetes-props.el" "kubernetes-state.el"
+;;;;;; "kubernetes-timers.el" "kubernetes-utils.el" "kubernetes-vars.el"
+;;;;;; "kubernetes-yaml.el" "kubernetes.el") (22902 775 708807 921000))
+
+;;;***
+
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; End:
+;;; kubernetes-autoloads.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-commands.el
@@ -0,0 +1,364 @@
+;;; 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-display-config "kubernetes-contexts")
+(autoload 'kubernetes-display-configmap "kubernetes-configmaps")
+(autoload 'kubernetes-display-deployment "kubernetes-deployments")
+(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))
+ (`(: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))
+ (_
+ (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))
+ (`(: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)))
+ (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-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-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.
+
+Inspecs 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))
+ (`(: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")
+ 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))))
+
+ (kubernetes-kubectl-config-use-context kubernetes-props
+ (kubernetes-state)
+ context
+ (lambda (_)
+ (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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-commands.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-configmaps.el
@@ -0,0 +1,141 @@
+;;; 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
+ (propertize (format "%-45s %6s %6s" "Name" "Data" "Age")
+ 'face 'magit-section-heading))
+
+(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)
+ (line `(line ,(concat
+ ;; Name
+ (format "%-45s " (kubernetes-utils-ellipsize name 45))
+
+ ;; Data
+ (propertize (format "%6s " (seq-length data)) 'face 'magit-dimmed)
+
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
+ (propertize (format "%6s" (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)]
+ `(section (configmaps-container ,hidden)
+ (header-with-count "Configmaps" ,configmaps)
+ (indent
+ (columnar-loading-container ,configmaps ,kubernetes-configmaps--column-heading
+ ,(--map `(configmap ,state ,it) configmaps)))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-configmaps-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-configmaps-process-live-p)
+ (kubernetes-process-set-poll-configmaps-process
+ (kubernetes-kubectl-get-configmaps kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-configmaps response)
+ (when interactive
+ (message "Updated configmaps.")))
+ (lambda ()
+ (kubernetes-process-release-poll-configmaps-process))))))
+
+(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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-configmaps.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-contexts.el
@@ -0,0 +1,88 @@
+;;; 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
+
+(defun kubernetes-contexts-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-config-process-live-p)
+ (kubernetes-process-set-poll-config-process
+ (kubernetes-kubectl-config-view kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-config response)
+ (when interactive
+ (message "Updated config.")))
+ (lambda ()
+ (kubernetes-process-release-poll-config-process))))))
+
+
+;; 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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-contexts.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-deployments.el
@@ -0,0 +1,199 @@
+;;; 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
+ (propertize (format "%-45s %10s %10s %10s %6s" "Name" "Replicas" "UpToDate" "Available" "Age")
+ 'face 'magit-section-heading))
+
+(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))
+
+ (line `(line ,(concat
+ ;; Name
+ (format "%-45s " (kubernetes-utils-ellipsize name 45))
+
+ ;; Replicas (current/desired)
+ (let ((str (format "%s/%s" current desired)))
+ (cond
+ ((zerop desired)
+ (format "%10s " str))
+ ((zerop current)
+ (propertize (format "%10s " str) 'face 'warning))
+ ((/= current desired)
+ (format "%10s " str))
+ (t
+ (propertize (format "%10s " str) 'face 'magit-dimmed))))
+
+ ;; Up-to-date
+ (cond
+ ((zerop desired)
+ (format "%10s " up-to-date))
+ ((zerop up-to-date)
+ (propertize (format "%10s " up-to-date) 'face 'warning))
+ (t
+ (propertize (format "%10s " up-to-date) 'face 'magit-dimmed)))
+
+ ;; Available
+ (cond
+ ((zerop desired)
+ (format "%10s " available))
+ ((zerop available)
+ (propertize (format "%10s " available) 'face 'warning))
+ (t
+ (propertize (format "%10s " available) 'face 'magit-dimmed)))
+
+
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
+ (propertize (format "%6s" (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)]
+ `(section (deployments-container ,hidden)
+ (header-with-count "Deployments" ,deployments)
+ (indent
+ (columnar-loading-container ,deployments ,kubernetes-deployments--column-heading
+ ,(--map `(deployment ,state ,it) deployments)))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-deployments-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-deployments-process-live-p)
+ (kubernetes-process-set-poll-deployments-process
+ (kubernetes-kubectl-get-deployments kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-deployments response)
+ (when interactive
+ (message "Updated deployments.")))
+ (lambda ()
+ (kubernetes-process-release-poll-deployments-process))))))
+
+(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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-deployments.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-errors.el
@@ -0,0 +1,31 @@
+;;; 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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-errors.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-jobs.el
@@ -0,0 +1,185 @@
+;;; 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
+ (propertize (format "%-45s %10s %6s" "Name" "Successful" "Age")
+ 'face 'magit-section-heading))
+
+(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))
+
+ (line (concat
+ ;; Name
+ (let ((name-str (format "%-45s " (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 "%8s " successful) 'face 'magit-dimmed)
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
+ (propertize (format "%6s" (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)]
+ `(section (jobs-container ,hidden)
+ (header-with-count "Jobs" ,jobs)
+ (indent
+ (columnar-loading-container ,jobs ,kubernetes-jobs--column-heading
+ ,(--map `(job ,state ,it) jobs)))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-jobs-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-jobs-process-live-p)
+ (kubernetes-process-set-poll-jobs-process
+ (kubernetes-kubectl-get-jobs kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-jobs response)
+ (when interactive
+ (message "Updated jobs.")))
+ (lambda ()
+ (kubernetes-process-release-poll-jobs-process))))))
+
+(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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-jobs.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-kubectl.el
@@ -0,0 +1,382 @@
+;;; 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-already-set (kubernetes-props-get-last-error props))
+ (process-killed-manually (string-match-p (rx bol (* space) "killed:" (* space) "9" (* space) eol) status)))
+ (unless (or process-killed-manually last-error-already-set)
+ (kubernetes-props-message props "kubernetes command failed. See the overview buffer for details.")))))
+
+(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" "--show-all" "-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-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-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-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-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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-kubectl.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-labels.el
@@ -0,0 +1,83 @@
+;;; 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))))
+ `(section (root nil)
+ (section (query-header nil)
+ (key-value 10 "Label" ,(propertize query 'face 'kubernetes-selector))
+ (padding))
+
+ (indent
+ (columnar-loading-container ,pods
+ ,kubernetes-pods-column-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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-labels.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-loading-container.el
@@ -0,0 +1,87 @@
+;;; 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 loading-container (resource-vector &rest loaded-content)
+ `(emptiness-loading-discriminator
+ ,resource-vector
+
+ :on-loading
+ (propertize (face kubernetes-progress-indicator) (line "Fetching..."))
+
+ :on-empty
+ (propertize (face magit-dimmed) (line "None."))
+
+ :on-populated ,loaded-content))
+
+(kubernetes-ast-define-component columnar-loading-container (resource-vector column-header &rest loaded-content)
+ `(emptiness-loading-discriminator
+ ,resource-vector
+
+ :on-loading
+ ((line ,column-header)
+ (propertize (face kubernetes-progress-indicator) (line "Fetching...")))
+
+ :on-empty
+ (propertize (face magit-dimmed) (line "None."))
+
+ :on-populated
+ ((line ,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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-loading-container.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-logs.el
@@ -0,0 +1,132 @@
+;;; 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)
+ (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
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-logs.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-modes.el
@@ -0,0 +1,92 @@
+;;; kubernetes-modes.el --- Base modes for Kubernetes. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'magit)
+(require 'subr-x)
+
+(autoload 'kubernetes-config-popup "kubernetes-popups")
+(autoload 'kubernetes-copy-thing-at-point "kubernetes-commands")
+(autoload 'kubernetes-describe-popup "kubernetes-popups")
+(autoload 'kubernetes-exec-popup "kubernetes-popups")
+(autoload 'kubernetes-execute-marks "kubernetes-commands")
+(autoload 'kubernetes-labels-popup "kubernetes-popups")
+(autoload 'kubernetes-logs-popup "kubernetes-popups")
+(autoload 'kubernetes-mark-for-delete "kubernetes-commands")
+(autoload 'kubernetes-navigate "kubernetes-commands")
+(autoload 'kubernetes-overview-popup "kubernetes-popups")
+(autoload 'kubernetes-refresh "kubernetes-commands")
+(autoload 'kubernetes-unmark "kubernetes-commands")
+(autoload 'kubernetes-unmark-all "kubernetes-commands")
+
+;;;###autoload
+(define-derived-mode kubernetes-display-thing-mode kubernetes-mode "Kubernetes Object"
+ "Mode for inspecting a Kubernetes object.
+
+\\{kubernetes-display-thing-mode-map}"
+ :group 'kubernetes)
+
+;;;###autoload
+(defvar kubernetes-mode-map
+ (let ((keymap (make-sparse-keymap)))
+ ;; Section controls
+ (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)
+ ;; Misc
+ (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
+(define-derived-mode kubernetes-mode special-mode "Kubernetes"
+ "Base mode for Kubernetes modes.
+
+\\{kubernetes-mode-map}"
+ :group 'kubernetes
+ (read-only-mode)
+ (buffer-disable-undo)
+ (setq truncate-lines t)
+ (setq-local line-move-visual t)
+ (setq show-trailing-whitespace nil)
+ (setq list-buffers-directory (abbreviate-file-name default-directory))
+ (hack-dir-local-variables-non-file-buffer)
+ (make-local-variable 'text-property-default-nonsticky)
+ (push (cons 'keymap t) text-property-default-nonsticky)
+ (push (cons 'kubernetes-nav t) text-property-default-nonsticky)
+ (push (cons 'kubernetes-copy t) text-property-default-nonsticky)
+ (add-hook 'post-command-hook #'magit-section-update-highlight t t)
+ (setq-local redisplay-highlight-region-function 'magit-highlight-region)
+ (setq-local redisplay-unhighlight-region-function 'magit-unhighlight-region)
+ (when (bound-and-true-p global-linum-mode)
+ (linum-mode -1))
+ (when (and (fboundp 'nlinum-mode)
+ (bound-and-true-p global-nlinum-mode))
+ (nlinum-mode -1)))
+
+(provide 'kubernetes-modes)
+
+;;; kubernetes-modes.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-modes.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-namespaces.el
@@ -0,0 +1,64 @@
+;;; kubernetes-namespaces.el --- Helpers for Kubernetes namespaces. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'kubernetes-kubectl)
+(require 'kubernetes-process)
+(require 'kubernetes-props)
+(require 'kubernetes-state)
+(require 'kubernetes-yaml)
+
+
+;; Requests and state management
+
+(defun kubernetes-namespaces-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-namespaces-process-live-p)
+ (kubernetes-process-set-poll-namespaces-process
+ (kubernetes-kubectl-get-namespaces kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-namespaces response)
+ (when interactive
+ (message "Updated namespaces.")))
+ (lambda ()
+ (kubernetes-process-release-poll-namespaces-process))))))
+
+
+;; Displaying namespaces
+
+(defun kubernetes-namespaces--read-name (state)
+ "Read a namespace name from the user.
+
+STATE is the current application state.
+
+Update the namespace state if it not set yet."
+ (-let* (((&alist 'items namespaces)
+ (or (kubernetes-state-namespaces state)
+ (progn
+ (message "Getting namespaces...")
+ (let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-namespaces)))
+ (kubernetes-state-update-namespaces response)
+ response))))
+ (namespaces (append namespaces nil))
+ (names (-map #'kubernetes-state-resource-name namespaces)))
+ (completing-read "Namespace: " names nil t)))
+
+;;;###autoload
+(defun kubernetes-display-namespace (namespace-name state)
+ "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."
+ (interactive (let ((state (kubernetes-state)))
+ (list (kubernetes-namespaces--read-name state) state)))
+ (if-let (namespace (kubernetes-state-lookup-namespace namespace-name state))
+ (select-window
+ (display-buffer
+ (kubernetes-yaml-make-buffer kubernetes-display-namespace-buffer-name namespace)))
+ (error "Unknown namespace: %s" namespace-name)))
+
+
+(provide 'kubernetes-namespaces)
+
+;;; kubernetes-namespaces.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-namespaces.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-overview.el
@@ -0,0 +1,361 @@
+;;; kubernetes-overview.el --- Utilities for managing the overview buffer. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'subr-x)
+
+(require 'kubernetes-ast)
+(require 'kubernetes-commands)
+(require 'kubernetes-configmaps)
+(require 'kubernetes-contexts)
+(require 'kubernetes-deployments)
+(require 'kubernetes-errors)
+(require 'kubernetes-jobs)
+(require 'kubernetes-loading-container)
+(require 'kubernetes-modes)
+(require 'kubernetes-namespaces)
+(require 'kubernetes-pods)
+(require 'kubernetes-pod-line)
+(require 'kubernetes-popups)
+(require 'kubernetes-secrets)
+(require 'kubernetes-services)
+(require 'kubernetes-timers)
+
+(autoload 'kubernetes-utils-up-to-existing-dir "kubernetes-utils")
+
+
+;; Configmaps
+
+(defun kubernetes-overview--referenced-configmaps (state pod)
+ (-let* (((&alist 'items configmaps) (kubernetes-state-configmaps state))
+ (configmaps (append configmaps nil))
+ ((&alist 'spec (&alist 'volumes volumes 'containers containers)) pod)
+
+ (names-in-volumes
+ (->> volumes
+ (seq-mapcat
+ (lambda (volume)
+ (-when-let ((&alist 'configMap (&alist 'name name)) volume)
+ (list name))))))
+
+ (names-in-env
+ (->> containers
+ (seq-mapcat (-lambda ((&alist 'env env)) env))
+ (seq-mapcat
+ (lambda (env)
+ (-when-let ((&alist 'valueFrom (&alist 'configMapKeyRef (&alist 'name name))) env)
+ (list name))))))
+
+ (references (-uniq (-union names-in-volumes names-in-env))))
+
+ (seq-filter (-lambda ((&alist 'metadata (&alist 'name name)))
+ (member name references))
+ configmaps)))
+
+(defun kubernetes-overview--configmaps-for-deployment (state pods)
+ (->> pods
+ (seq-mapcat (lambda (pod) (kubernetes-overview--referenced-configmaps state pod)))
+ -non-nil
+ -uniq
+ (seq-sort (lambda (s1 s2)
+ (string< (kubernetes-state-resource-name s1)
+ (kubernetes-state-resource-name s2))))))
+
+(kubernetes-ast-define-component aggregated-configmap-line (state configmap)
+ (-let* ((pending-deletion (kubernetes-state-configmaps-pending-deletion state))
+ (marked-configmaps (kubernetes-state-marked-configmaps state))
+ ((&alist 'metadata (&alist 'name name )) configmap)
+ (line (cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,name))
+ ((member name marked-configmaps)
+ `(mark-for-delete ,name))
+ (t
+ name))))
+ `(section (,(intern (kubernetes-state-resource-name configmap)) t)
+ (nav-prop (:configmap-name ,name)
+ (copy-prop ,name (line ,line))))))
+
+(kubernetes-ast-define-component aggregated-configmaps (state configmaps)
+ `(section (configmaps nil)
+ (heading "Configmaps")
+ (indent ,(--map `(aggregated-configmap-line ,state ,it) configmaps))
+ (padding)))
+
+
+;; Secrets
+
+(defun kubernetes-overview--referenced-secrets (secrets pod)
+ (-let* (((&alist 'spec (&alist 'volumes vols 'containers containers)) pod)
+ (combined-env (seq-mapcat (-lambda ((&alist 'env env))
+ env)
+ containers))
+ (names-in-volumes
+ (seq-mapcat
+ (lambda (volume)
+ (-when-let ((&alist 'secret (&alist 'secretName name)) volume)
+ (list name)))
+ vols))
+
+ (names-in-env
+ (seq-mapcat
+ (lambda (env)
+ (-when-let ((&alist 'valueFrom (&alist 'secretKeyRef (&alist 'name name))) env)
+ (list name)))
+ combined-env))
+
+ (references (-union names-in-volumes names-in-env))
+ (matches (seq-filter (lambda (secret)
+ (member (kubernetes-state-resource-name secret) references))
+ secrets)))
+ (seq-sort (lambda (s1 s2)
+ (string< (kubernetes-state-resource-name s1)
+ (kubernetes-state-resource-name s2)))
+ matches)))
+
+(defun kubernetes-overview--secrets-for-deployment (state pods)
+ (-let* (((&alist 'items secrets) (kubernetes-state-secrets state))
+ (secrets (append secrets nil)))
+ (-non-nil (-uniq (seq-mapcat (lambda (pod)
+ (kubernetes-overview--referenced-secrets secrets pod))
+ pods)))))
+
+(kubernetes-ast-define-component aggregated-secret-line (state secret)
+ (-let* ((pending-deletion (kubernetes-state-secrets-pending-deletion state))
+ (marked-secrets (kubernetes-state-marked-secrets state))
+ ((&alist 'metadata (&alist 'name name )) secret)
+ (line (cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,name))
+ ((member name marked-secrets)
+ `(mark-for-delete ,name))
+ (t
+ name))))
+ `(section (,(intern (kubernetes-state-resource-name secret)) t)
+ (nav-prop (:secret-name ,name)
+ (copy-prop ,name (line ,line))))))
+
+(kubernetes-ast-define-component aggregated-secrets (state secrets)
+ `(section (secrets nil)
+ (heading "Secrets")
+ (indent ,(--map `(aggregated-secret-line ,state ,it) secrets))
+ (padding)))
+
+
+;; Pods
+
+(defun kubernetes-overview--pods-for-deployment (state deployment)
+ (-let* (((&alist 'spec (&alist 'selector (&alist 'matchLabels (&alist 'name selector-name)))) deployment)
+ ((&alist 'items pods) (kubernetes-state-pods state))
+ (pods (append pods nil)))
+ (nreverse (seq-reduce
+ (lambda (acc pod)
+ (if (equal selector-name (kubernetes-state-resource-label pod))
+ (cons pod acc)
+ acc))
+ pods
+ nil))))
+
+(kubernetes-ast-define-component aggregated-pods (state deployment pods)
+ (-let [(&alist 'spec (&alist
+ 'replicas replicas
+ 'selector (&alist 'matchLabels
+ (&alist 'name selector-name
+ 'component component-name)
+ 'matchExpressions match-expressions)))
+ deployment]
+ `(section (pods nil)
+ (heading "Pods")
+ (indent
+ ,(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))))
+
+ (key-value 12 "Replicas" ,(format "%s" (or replicas 1)))
+
+ (loading-container ,(kubernetes-state-pods state)
+ ,(seq-map (lambda (pod) `(pod-line ,state ,pod)) pods)))
+
+ (padding))))
+
+
+;; Deployment
+
+(kubernetes-ast-define-component aggregated-deployment-detail (deployment)
+ (-let [(&alist 'metadata (&alist 'namespace ns 'creationTimestamp time)
+ 'spec (&alist
+ 'paused paused
+ 'strategy (&alist
+ 'type strategy-type
+ 'rollingUpdate rolling-update)))
+ deployment]
+ `(,(when paused `(line (propertize (face warning) "Deployment Paused")))
+ (section (namespace nil)
+ (nav-prop (:namespace-name ,ns)
+ (key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace))))
+ ,(-if-let ((&alist 'maxSurge surge 'maxUnavailable unavailable) rolling-update)
+ `(section (strategy t)
+ (heading (key-value 12 "Strategy" ,strategy-type))
+ (indent
+ ((key-value 12 "Max Surge" ,(format "%s" surge))
+ (key-value 12 "Max Unavailable" ,(format "%s" unavailable)))))
+ `(key-value 12 "Strategy" ,strategy-type))
+ (key-value 12 "Created" ,time))))
+
+(kubernetes-ast-define-component aggregated-deployment (state deployment)
+ (let* ((pods (kubernetes-overview--pods-for-deployment state deployment))
+ (configmaps (kubernetes-overview--configmaps-for-deployment state pods))
+ (secrets (kubernetes-overview--secrets-for-deployment state pods)))
+ `(section (,(intern (kubernetes-state-resource-name deployment)) t)
+ (heading (deployment-line ,state ,deployment))
+ (section (details nil)
+ (indent
+ (aggregated-deployment-detail ,deployment)
+ (padding)
+ (aggregated-pods ,state ,deployment ,pods)
+ ,(when configmaps
+ `(aggregated-configmaps ,state ,configmaps))
+ ,(when secrets
+ `(aggregated-secrets ,state ,secrets)))))))
+
+
+;; Main Components
+
+(kubernetes-ast-define-component aggregated-view (state &optional hidden)
+ (-let [(state-set-p &as &alist 'items deployments) (kubernetes-state-deployments state)]
+ `(section (overview-container ,hidden)
+ (header-with-count "Deployments" ,deployments)
+ (indent
+ (columnar-loading-container ,deployments
+ ,kubernetes-deployments--column-heading
+ ,@(--map `(aggregated-deployment ,state ,it) deployments)))
+ (padding))))
+
+(defun kubernetes-overview-render (state)
+ (let ((sections (kubernetes-state-overview-sections state)))
+ `(section (root nil)
+ ,(kubernetes-errors-render state)
+ ,(when (member 'context sections)
+ (kubernetes-contexts-render state))
+ ,(when (member 'configmaps sections)
+ `(configmaps-list ,state))
+ ,(when (member 'deployments sections)
+ `(deployments-list ,state))
+ ,(when (member 'jobs sections)
+ `(jobs-list ,state))
+ ,(when (member 'overview sections)
+ `(aggregated-view ,state))
+ ,(when (member 'pods sections)
+ `(pods-list ,state))
+ ,(when (member 'secrets sections)
+ `(secrets-list ,state))
+ ,(when (member 'services sections)
+ `(services-list ,state)))))
+
+
+;; Overview buffer.
+
+(defun kubernetes-overview--redraw-buffer ()
+ "Redraws the main buffer using the current state."
+ (when-let (buf (get-buffer kubernetes-overview-buffer-name))
+ (with-current-buffer buf
+ ;; If a region is active, a redraw would affect the region in
+ ;; unpredictable ways.
+ (unless (region-active-p)
+ ;; Suppress redrawing if the overview is not selected. This prevents
+ ;; point from jumping around when a magit popup is open.
+ (when (member (selected-window) (get-buffer-window-list buf))
+ (kubernetes-utils--save-window-state
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (kubernetes-ast-eval (kubernetes-overview-render (kubernetes-state)))))
+
+ ;; Force the section at point to highlight.
+ (magit-section-update-highlight))))))
+
+(defun kubernetes-overview--poll (&optional verbose)
+ (kubernetes-configmaps-refresh verbose)
+ (kubernetes-contexts-refresh verbose)
+ (kubernetes-jobs-refresh verbose)
+ (kubernetes-deployments-refresh verbose)
+ (kubernetes-namespaces-refresh verbose)
+ (kubernetes-pods-refresh verbose)
+ (kubernetes-secrets-refresh verbose)
+ (kubernetes-services-refresh verbose))
+
+(defun kubernetes-overview--initialize-buffer ()
+ "Called the first time the overview buffer is opened to set up the buffer."
+ (let ((buf (get-buffer-create kubernetes-overview-buffer-name)))
+ (with-current-buffer buf
+ (kubernetes-overview-mode)
+ (add-hook 'kubernetes-redraw-hook #'kubernetes-overview--redraw-buffer)
+ (add-hook 'kubernetes-poll-hook #'kubernetes-overview--poll)
+ (kubernetes-timers-initialize-timers)
+ (kubernetes-overview--redraw-buffer)
+ (add-hook 'kill-buffer-hook (kubernetes-utils-make-cleanup-fn buf) nil t))
+ buf))
+
+(defun kubernetes-overview-set-sections (sections)
+ "Set which sections are displayed in the overview.
+
+SECTIONS is a list of sections to display. See
+`kubernetes-overview-custom-views-alist' and
+`kubernetes-overview-views-alist' for possible values."
+ (interactive
+ (let* ((views (append kubernetes-overview-custom-views-alist kubernetes-overview-views-alist))
+ (names (-uniq (--map (symbol-name (car it)) views)))
+ (choice (intern (completing-read "Overview view: " names nil t))))
+ (list (alist-get choice views))))
+
+ (kubernetes-state-update-overview-sections sections)
+ (kubernetes-state-trigger-redraw))
+
+(defvar kubernetes-overview-mode-map
+ (let ((keymap (make-sparse-keymap)))
+ (define-key keymap (kbd "v") #'kubernetes-overview-set-sections)
+ keymap)
+ "Keymap for `kubernetes-overview-mode'.")
+
+;;;###autoload
+(define-derived-mode kubernetes-overview-mode kubernetes-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}"
+ :group 'kubernetes)
+
+;;;###autoload
+(defun kubernetes-overview ()
+ "Display an overview buffer for Kubernetes."
+ (interactive)
+ (let ((dir default-directory)
+ (buf (kubernetes-overview--initialize-buffer)))
+ (kubernetes-commands-display-buffer buf)
+ (with-current-buffer buf
+ (cd (kubernetes-utils-up-to-existing-dir dir)))
+ (message (substitute-command-keys "\\<kubernetes-overview-mode-map>Type \\[kubernetes-overview-set-sections] to switch between resources, and \\[kubernetes-overview-popup] for usage."))))
+
+
+(provide 'kubernetes-overview)
+
+;;; kubernetes-overview.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-overview.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-pkg.el
@@ -0,0 +1,7 @@
+(define-package "kubernetes" "20170523.1517" "Magit-like porcelain for Kubernetes."
+ '((emacs "25.1")
+ (dash "2.12.0")
+ (magit "2.8.0")))
+;; Local Variables:
+;; no-byte-compile: t
+;; End:
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-pod-line.el
@@ -0,0 +1,51 @@
+;;; kubernetes-pod-line.el --- Component for individual pod lines. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'kubernetes-ast)
+(require 'kubernetes-state)
+(require 'kubernetes-utils)
+
+(defun kubernetes-pod-line-ok-p (pod)
+ (-let [(&alist 'status (&alist 'containerStatuses containers 'phase phase)) pod pod]
+ (unless (seq-empty-p containers)
+ (-let* (([(&alist 'state pod-state)] containers)
+ (pod-state (or (alist-get 'reason (alist-get 'waiting pod-state)) phase)))
+ (member (downcase pod-state) '("running" "containercreating" "terminated"
+ "succeeded"))))))
+
+(kubernetes-ast-define-component pod-line (state pod)
+ (-let* ((marked-pods (kubernetes-state-marked-pods state))
+ (pending-deletion (kubernetes-state-pods-pending-deletion state))
+ ((&alist 'metadata (&alist 'name name) 'status (&alist 'containerStatuses containers 'phase phase)) pod)
+ ([(&alist 'state pod-state)] containers)
+ (pod-state (or (alist-get 'reason (alist-get 'waiting pod-state)) phase))
+ (state-face
+ (cond
+ ((member (downcase pod-state) '("running" "containercreating" "terminated"))
+ 'magit-dimmed)
+ ((member (downcase pod-state) '("runcontainererror" "crashloopbackoff"))
+ 'error)
+ ((equal (downcase pod-state) "succeeded")
+ 'success)
+ (t
+ 'warning)))
+ (line
+ (concat (propertize (format "%-11s " (kubernetes-utils-ellipsize pod-state 11)) 'face state-face)
+ name)))
+
+ `(section (,(intern (kubernetes-state-resource-name pod)) t)
+ (nav-prop (:pod-name ,name)
+ (copy-prop ,name
+ (line ,(cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,line))
+ ((member name marked-pods)
+ `(mark-for-delete ,line))
+ (t
+ line))))))))
+
+
+(provide 'kubernetes-pod-line)
+
+;;; kubernetes-pod-line.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-pod-line.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-pods.el
@@ -0,0 +1,182 @@
+;;; kubernetes-pods.el --- Rendering for Kubernetes pods -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'dash)
+(require 'seq)
+
+(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-pods-column-heading
+ (propertize (format "%-45s %-10s %-5s %6s %6s" "Name" "Status" "Ready" "Restarts" "Age")
+ 'face 'magit-section-heading))
+
+(kubernetes-ast-define-component pod-view-detail (pod)
+ (-let ((detail (lambda (k v)
+ (when v
+ `(key-value 12 ,k ,v))))
+
+ ((&alist 'metadata (&alist 'namespace ns 'labels (&alist 'name label-name))
+ 'status (&alist 'containerStatuses [(&alist 'image image 'name name)]
+ 'hostIP host-ip
+ 'podIP pod-ip
+ 'startTime start-time))
+ pod))
+ `(,(funcall detail "Name" name)
+ ,(when label-name
+ `(section (selector nil)
+ (nav-prop (:selector ,label-name)
+ ,(funcall detail "Label" (propertize label-name 'face 'kubernetes-selector)))))
+ ,(when ns
+ `(section (namespace nil)
+ (nav-prop (:namespace-name ,ns)
+ (key-value 12 "Namespace" ,(propertize ns 'face 'kubernetes-namespace)))))
+ ,(funcall detail "Image" image)
+ ,(funcall detail "Host IP" host-ip)
+ ,(funcall detail "Pod IP" pod-ip)
+ ,(funcall detail "Started" start-time))))
+
+(kubernetes-ast-define-component pod-view-line (state pod)
+ (-let* ((current-time (kubernetes-state-current-time state))
+ (marked-pods (kubernetes-state-marked-pods state))
+ (pending-deletion (kubernetes-state-pods-pending-deletion state))
+ ((&alist 'metadata (&alist 'name name)
+ 'status (&alist 'containerStatuses containers
+ 'startTime start-time
+ 'phase phase))
+ pod)
+ ([(&alist 'restartCount restarts 'state pod-state)] containers)
+ (pod-state (or (alist-get 'reason (alist-get 'waiting pod-state))
+ phase))
+ (str
+ (concat
+ ;; Name
+ (format "%-45s " (kubernetes-utils-ellipsize name 45))
+
+ ;; State
+ (let ((s (format "%-10s " (kubernetes-utils-ellipsize pod-state 10))))
+ (if (equal pod-state "Running") (propertize s 'face 'magit-dimmed) s))
+
+ ;; Count
+ (format "%5s "
+ (let* ((n-ready (seq-count (-lambda ((it &as &alist 'ready r))
+ (eq r t))
+ containers))
+ (count-str (format "%s/%s" n-ready (seq-length containers))))
+ (if (zerop n-ready)
+ count-str
+ (propertize count-str 'face 'magit-dimmed))))
+
+ ;; Restarts
+ (let ((s (format "%8s " restarts)))
+ (cond
+ ((equal 0 restarts)
+ (propertize s 'face 'magit-dimmed))
+ ((<= kubernetes-pod-restart-warning-threshold restarts)
+ (propertize s 'face 'warning))
+ (t
+ s)))
+
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp start-time))))
+ (propertize (format "%8s" (kubernetes-utils-time-diff-string start current-time))
+ 'face 'magit-dimmed))))
+
+ (str (cond
+ ((member (downcase pod-state) '("running" "containercreating" "terminated"))
+ str)
+ ((member (downcase pod-state) '("runcontainererror" "crashloopbackoff"))
+ (propertize str 'face 'error))
+ (t
+ (propertize str 'face 'warning))))
+ (line `(line ,str)))
+
+ `(nav-prop (:pod-name ,name)
+ (copy-prop ,name
+ ,(cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,line))
+ ((member name marked-pods)
+ `(mark-for-delete ,line))
+ (t
+ line))))))
+
+(kubernetes-ast-define-component pod (state pod)
+ `(section (,(intern (kubernetes-state-resource-name pod)) t)
+ (heading (pod-view-line ,state ,pod))
+ (indent
+ (section (details nil)
+ (pod-view-detail ,pod)
+ (padding)))))
+
+(defun kubernetes-pods--succeeded-job-pod-p (pod)
+ (-let [(&alist 'status (&alist 'phase phase)) pod]
+ (equal phase "Succeeded")))
+
+(kubernetes-ast-define-component pods-list (state &optional hidden)
+ (-let [(&alist 'items pods) (kubernetes-state-pods state)]
+ `(section (pods-container ,hidden)
+ (header-with-count "Pods" ,pods)
+ (indent
+ (columnar-loading-container ,pods ,kubernetes-pods-column-heading
+ ,@(--map `(pod ,state ,it)
+ (-remove #'kubernetes-pods--succeeded-job-pod-p (append pods nil)))))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-pods-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-pods-process-live-p)
+ (kubernetes-process-set-poll-pods-process
+ (kubernetes-kubectl-get-pods kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-pods response)
+ (when interactive
+ (message "Updated pods.")))
+ (lambda ()
+ (kubernetes-process-release-poll-pods-process))))))
+
+(defun kubernetes-pods-delete-marked (state)
+ (let ((names (kubernetes-state-marked-pods state)))
+ (dolist (name names)
+ (kubernetes-state-delete-pod name)
+ (kubernetes-kubectl-delete-pod kubernetes-props state name
+ (lambda (_)
+ (message "Deleting pod %s succeeded." name))
+ (lambda (_)
+ (message "Deleting pod %s failed" name)
+ (kubernetes-state-mark-pod name))))
+ (kubernetes-state-trigger-redraw)))
+
+;; Interactive commands
+
+;;;###autoload
+(defun kubernetes-display-pod (pod-name state)
+ "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."
+ (interactive (let ((state (kubernetes-state)))
+ (list (kubernetes-utils-read-pod-name state) state)))
+ (if-let (pod (kubernetes-state-lookup-pod pod-name state))
+ (select-window
+ (display-buffer
+ (kubernetes-yaml-make-buffer kubernetes-pod-buffer-name pod)))
+ (error "Unknown pod: %s" pod-name)))
+
+
+(provide 'kubernetes-pods)
+
+;;; kubernetes-pods.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-pods.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-popups.el
@@ -0,0 +1,133 @@
+;;; kubernetes-popups.el --- Magit popups for Kubernetes buffers. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'magit-popup)
+(require 'kubernetes-state)
+
+(defgroup kubernetes nil
+ "Emacs porcelain for Kubernetes."
+ :group 'tools
+ :prefix "kubernetes-")
+
+
+;; Utilities
+
+(defun kubernetes-popups--read-existing-file (prompt &optional default)
+ (read-file-name prompt nil default t nil #'file-regular-p))
+
+(defun kubernetes-popups--read-server-and-port (&optional _option defaults)
+ (-let* (((server port) (split-string (or defaults "") ":" t))
+ (port (or (ignore-errors (string-to-number port)) 8080)))
+ (format "%s:%s" (read-string "Server: " server) (read-number "Port: " port))))
+
+
+;; Popup definitions
+
+(magit-define-popup kubernetes-logs-popup
+ "Popup console for pod logging commands."
+ :group 'kubernetes
+ :switches
+ '((?p "Print logs for previous instances of the container in this pod" "-p"))
+ :options
+ '("Options for customizing logging behaviour"
+ (?t "Number of lines to display" "--tail=" read-number)
+ "Time controls"
+ (?s "Since relative time" "--since=" kubernetes-utils-read-time-value)
+ (?d "Since absolute datetime" "--since-time=" kubernetes-utils-read-iso-datetime))
+ :actions
+ '((?l "Logs" kubernetes-logs-fetch-all)
+ (?f "Logs (stream and follow)" kubernetes-logs-follow))
+ :max-action-columns 2
+ :default-action 'kubernetes-logs)
+
+(magit-define-popup kubernetes-overview-popup
+ "Popup console for showing an overview of available popup commands."
+ :group 'kubernetes
+ :actions
+ '("Environment"
+ (?c "Configuration" kubernetes-config-popup)
+ "Marks"
+ (?D "Delete" kubernetes-mark-for-delete)
+ (?u "Unmark" kubernetes-unmark)
+ (?U "Unmark all" kubernetes-unmark-all)
+ "Popup commands"
+ (?d "Describe" kubernetes-describe-popup)
+ (?e "Exec" kubernetes-exec-popup)
+ (?L "Labels" kubernetes-labels-popup)
+ (?l "Logs" kubernetes-logs-popup)
+ "Misc"
+ (?h "Describe mode and keybindings" describe-mode)))
+
+(magit-define-popup kubernetes-exec-popup
+ "Popup console for exec commands for POD."
+ :group 'kubernetes
+ :default-arguments '("-i" "-t")
+ :switches
+ '((?i "Pass stdin to container" "-i" t)
+ (?t "Stdin is a TTY" "-t" t))
+ :actions
+ '((?e "Exec" kubernetes-exec-into))
+
+ :default-action 'kubernetes-exec-into)
+
+(magit-define-popup kubernetes-describe-popup
+ "Popup console for describe commands."
+ :group 'kubernetes
+ :actions
+ '((?d "Dwim" kubernetes-describe-dwim)
+ (?p "Pod" kubernetes-describe-pod))
+ :default-action 'kubernetes-logs)
+
+(magit-define-popup kubernetes-labels-popup
+ "Popup console for commands relating to labels."
+ :group 'kubernetes
+ :actions
+ '((?p "Pods" kubernetes-show-pods-for-label))
+ :default-action 'kubernetes-show-pods-for-label)
+
+
+;; Config popup
+;;
+;; The macro definition is expanded here and modified to support marshalling
+;; state between the state manager and the magit popup's global state.
+
+(defconst kubernetes-config-popup
+ (list :group 'kubernetes
+ :variable 'kubernetes-kubectl-flags
+ :options
+ `("Configuration"
+ (?f "Kubeconfig file" "--kubeconfig=" kubernetes-popups--read-existing-file)
+ (?l "Cluster name in config" "--cluster=" read-string)
+ (?s "Server address and port" "--server=" kubernetes-popups--read-server-and-port)
+ (?u "User in kubeconfig" "--user=" read-string)
+ "Authentication"
+ (?a "CA cert file" "--certificate-authority=" kubernetes-popups--read-existing-file)
+ (?k "Client key file" "--client-key=" kubernetes-popups--read-existing-file)
+ (?r "Client cert file" "--client-certificate=" kubernetes-popups--read-existing-file)
+ (?t "API token" "--token=" read-string))
+ :actions
+ '((?c "Change context" kubernetes-use-context)
+ (?n "Set namespace" kubernetes-set-namespace))))
+
+(defun kubernetes-popups--update-kubectl-state ()
+ ;; HACK: Need to use internal magit vars, since this is run inside the popup
+ ;; refresh hook.
+ (when (eq magit-this-popup 'kubernetes-config-popup)
+ (kubernetes-state-update-kubectl-flags (magit-popup-get-args))))
+
+(defun kubernetes-config-popup (&optional arg)
+ "Popup console for showing an overview of available config commands.
+
+With ARG, execute default command."
+ (interactive "P")
+ (let ((flags (kubernetes-state-kubectl-flags (kubernetes-state))))
+ (setq kubernetes-kubectl-flags flags))
+ (add-hook 'magit-refresh-popup-buffer-hook #'kubernetes-popups--update-kubectl-state)
+ (magit-invoke-popup 'kubernetes-config-popup nil arg))
+
+(magit-define-popup-keys-deferred 'kubernetes-config-popup)
+
+(provide 'kubernetes-popups)
+
+;;; kubernetes-popups.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-popups.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-process.el
@@ -0,0 +1,79 @@
+;;; kubernetes-process.el --- Process management. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'subr-x)
+
+(defun kubernetes-process-kill-quietly (proc &optional _signal)
+ (when proc
+ (set-process-sentinel proc nil)
+ (set-process-query-on-exit-flag proc nil)
+ (let ((kill-buffer-query-functions nil)
+ (buf (process-buffer proc)))
+ (ignore-errors (kill-process proc))
+ (ignore-errors (delete-process proc))
+ (ignore-errors (kill-buffer buf)))))
+
+
+;;; Background polling processes.
+
+(defmacro kubernetes-process--define-polling-process (resource)
+ "Create resource polling-related definitions.
+
+RESOURCE is the name of the resource as a symbol.
+
+Defines the following functions:
+
+- `kubernetes-process-set-poll-RESOURCE-process'
+- `kubernetes-process-release-poll-RESOURCE-process'
+- `kubernetes-process-poll-RESOURCE-process'."
+ (unless (symbolp resource) (error "RESOURCE must be a symbol"))
+ (let ((proc-var-name (intern (format "kubernetes--internal-poll-%s-process" resource)))
+ (proc-live-p (intern (format "kubernetes-process-poll-%s-process-live-p" resource)))
+ (releaser-name (intern (format "kubernetes-process-release-poll-%s-process" resource)))
+ (setter-name (intern (format "kubernetes-process-set-poll-%s-process" resource))))
+ `(progn
+ (defvar ,proc-var-name nil
+ "Variable used to coordinate polling access to resources.
+
+Do not use this variable directly. Instead, use its corresponding accessors.")
+
+ (defun ,proc-live-p ()
+ "Get the polling process for this resource if it is running."
+ (when-let (proc ,proc-var-name)
+ (when (process-live-p proc)
+ proc)))
+
+ (defun ,setter-name (proc)
+ "Set the polling process to PROC."
+ (,releaser-name)
+ (setq ,proc-var-name proc))
+
+ (defun ,releaser-name ()
+ "Kill the existing polling process, if any."
+ (kubernetes-process-kill-quietly ,proc-var-name)
+ (setq ,proc-var-name nil)))))
+
+(kubernetes-process--define-polling-process config)
+(kubernetes-process--define-polling-process configmaps)
+(kubernetes-process--define-polling-process deployments)
+(kubernetes-process--define-polling-process jobs)
+(kubernetes-process--define-polling-process namespaces)
+(kubernetes-process--define-polling-process pods)
+(kubernetes-process--define-polling-process secrets)
+(kubernetes-process--define-polling-process services)
+
+(defun kubernetes-process-kill-polling-processes ()
+ (kubernetes-process-release-poll-config-process)
+ (kubernetes-process-release-poll-configmaps-process)
+ (kubernetes-process-release-poll-deployments-process)
+ (kubernetes-process-release-poll-jobs-process)
+ (kubernetes-process-release-poll-namespaces-process)
+ (kubernetes-process-release-poll-pods-process)
+ (kubernetes-process-release-poll-secrets-process)
+ (kubernetes-process-release-poll-services-process))
+
+
+(provide 'kubernetes-process)
+
+;;; kubernetes-process.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-process.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-props.el
@@ -0,0 +1,27 @@
+;;; kubernetes-props.el --- Functions used to decouple modules for testability. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(defconst kubernetes-props
+ '((message . message)
+ (update-last-error . kubernetes-state-update-last-error)
+ (overview-buffer-selected-p . kubernetes-utils-overview-buffer-selected-p)
+ (get-last-error . (lambda ()
+ (kubernetes-state-last-error (kubernetes-state)))))
+ "Variable used to inject functions across modules.")
+
+(defun kubernetes-props-update-last-error (props message command time)
+ (funcall (alist-get 'update-last-error props) message command time))
+
+(defun kubernetes-props-get-last-error (props)
+ (funcall (alist-get 'get-last-error props)))
+
+(defun kubernetes-props-message (props fmt-string &rest args)
+ (apply (alist-get 'message props) fmt-string args))
+
+(defun kubernetes-props-overview-buffer-selected-p (props)
+ (funcall (alist-get 'overview-buffer-selected-p props)))
+
+(provide 'kubernetes-props)
+
+;;; kubernetes-props.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-props.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-secrets.el
@@ -0,0 +1,139 @@
+;;; kubernetes-secrets.el --- Rendering routines for Kubernetes secrets. -*- 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-secrets--column-heading
+ (propertize (format "%-45s %6s %6s" "Name" "Data" "Age")
+ 'face 'magit-section-heading))
+
+(kubernetes-ast-define-component secret-detail (secret)
+ (-let [(&alist 'metadata (&alist 'namespace ns 'creationTimestamp time)) secret]
+ `((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 secret-line (state secret)
+ (-let* ((current-time (kubernetes-state-current-time state))
+ (pending-deletion (kubernetes-state-secrets-pending-deletion state))
+ (marked-secrets (kubernetes-state-marked-secrets state))
+ ((&alist 'data data 'metadata (&alist 'name name 'creationTimestamp created-time))
+ secret)
+ (line `(line ,(concat
+ ;; Name
+ (format "%-45s " (kubernetes-utils-ellipsize name 45))
+
+ ;; Data
+ (propertize (format "%6s " (seq-length data)) 'face 'magit-dimmed)
+
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
+ (propertize (format "%6s" (kubernetes-utils-time-diff-string start current-time))
+ 'face 'magit-dimmed))))))
+
+ `(nav-prop (:secret-name ,name)
+ (copy-prop ,name
+ ,(cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,line))
+ ((member name marked-secrets)
+ `(mark-for-delete ,line))
+ (t
+ line))))))
+
+(kubernetes-ast-define-component secret (state secret)
+ `(section (,(intern (kubernetes-state-resource-name secret)) t)
+ (heading (secret-line ,state ,secret))
+ (section (details nil)
+ (indent
+ (secret-detail ,secret)
+ (padding)))))
+
+(kubernetes-ast-define-component secrets-list (state &optional hidden)
+ (-let [(&alist 'items secrets) (kubernetes-state-secrets state)]
+ `(section (secrets-container ,hidden)
+ (header-with-count "Secrets" ,secrets)
+ (indent
+ (columnar-loading-container ,secrets ,kubernetes-secrets--column-heading
+ ,(--map `(secret ,state ,it) secrets)))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-secrets-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-secrets-process-live-p)
+ (kubernetes-process-set-poll-secrets-process
+ (kubernetes-kubectl-get-secrets kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-secrets response)
+ (when interactive
+ (message "Updated secrets.")))
+ (lambda ()
+ (kubernetes-process-release-poll-secrets-process))))))
+
+(defun kubernetes-secrets-delete-marked (state)
+ (let ((names (kubernetes-state-marked-secrets state)))
+ (dolist (name names)
+ (kubernetes-state-delete-secret name)
+ (kubernetes-kubectl-delete-secret kubernetes-props state name
+ (lambda (_)
+ (message "Deleting secret %s succeeded." name))
+ (lambda (_)
+ (message "Deleting secret %s failed" name)
+ (kubernetes-state-mark-secret name))))
+ (kubernetes-state-trigger-redraw)))
+
+
+;; Displaying secrets.
+
+(defun kubernetes-secrets--read-name (state)
+ "Read a secret name from the user.
+
+STATE is the current application state.
+
+Update the secret state if it not set yet."
+ (-let* (((&alist 'items secrets)
+ (or (kubernetes-state-secrets state)
+ (progn
+ (message "Getting secrets...")
+ (let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-secrets)))
+ (kubernetes-state-update-secrets response)
+ response))))
+ (secrets (append secrets nil))
+ (names (-map #'kubernetes-state-resource-name secrets)))
+ (completing-read "Secret: " names nil t)))
+
+;;;###autoload
+(defun kubernetes-display-secret (secret-name state)
+ "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."
+ (interactive (let ((state (kubernetes-state)))
+ (list (kubernetes-secrets--read-name state) state)))
+ (if-let (secret (kubernetes-state-lookup-secret secret-name state))
+ (select-window
+ (display-buffer
+ (kubernetes-yaml-make-buffer kubernetes-display-secret-buffer-name secret)))
+ (error "Unknown secret: %s" secret-name)))
+
+
+(provide 'kubernetes-secrets)
+
+;;; kubernetes-secrets.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-secrets.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-services.el
@@ -0,0 +1,173 @@
+;;; kubernetes-services.el --- Rendering for Kubernetes services. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'dash)
+
+(require 'kubernetes-ast)
+(require 'kubernetes-kubectl)
+(require 'kubernetes-loading-container)
+(require 'kubernetes-modes)
+(require 'kubernetes-props)
+(require 'kubernetes-state)
+(require 'kubernetes-utils)
+(require 'kubernetes-vars)
+(require 'kubernetes-yaml)
+
+
+;; Components
+
+(defconst kubernetes-services--column-heading
+ (propertize (format "%-30s %15s %15s %6s" "Name" "Internal IP" "External IP" "Age")
+ 'face 'magit-section-heading))
+
+(kubernetes-ast-define-component service-details (service)
+ (-let ((detail
+ (lambda (key value)
+ (when value
+ `(key-value 15 ,key ,value))))
+
+ (format-ports
+ (-lambda ((&alist 'name name 'port port 'protocol prot))
+ (concat (when name (format "%s:" name))
+ (number-to-string port) "/" prot)))
+
+ ((&alist 'metadata (&alist 'namespace ns
+ 'creationTimestamp created-time
+ 'labels (&alist 'name label))
+ 'spec (&alist 'clusterIP internal-ip
+ 'externalIPs ips
+ 'ports ports
+ 'selector (&alist 'name selector)))
+ service))
+ (list
+ (when selector
+ `(section (selector nil)
+ (nav-prop (:selector ,selector) ,(funcall detail "Selector" (propertize selector 'face 'kubernetes-selector)))))
+ (funcall detail "Label" label)
+ (when ns
+ `(section (namespace nil)
+ (nav-prop (:namespace-name ,ns)
+ ,(funcall detail "Namespace" (propertize ns 'face 'kubernetes-namespace)))))
+ (funcall detail "Created" created-time)
+ (funcall detail "Internal IP" internal-ip)
+ (when-let (ips (append ips nil))
+ (funcall detail "External IPs" (string-join ips ", ")))
+ (funcall detail "Ports" (string-join (seq-map format-ports ports) ", ")))))
+
+(kubernetes-ast-define-component service-line (state service)
+ (-let* ((current-time (kubernetes-state-current-time state))
+ (pending-deletion (kubernetes-state-services-pending-deletion state))
+ (marked-services (kubernetes-state-marked-services state))
+ ((&alist 'metadata (&alist 'name name 'creationTimestamp created-time)
+ 'spec (&alist 'clusterIP internal-ip
+ 'externalIPs external-ips))
+ service)
+ (line `(line ,(concat
+ ;; Name
+ (format "%-30s " (kubernetes-utils-ellipsize name 30))
+
+ ;; Internal IP
+ (propertize (format "%15s " internal-ip) 'face 'magit-dimmed)
+
+ ;; External IP
+ (let ((ips (append external-ips nil)))
+ (propertize (format "%15s " (or (car ips) "")) 'face 'magit-dimmed))
+
+ ;; Age
+ (let ((start (apply #'encode-time (kubernetes-utils-parse-utc-timestamp created-time))))
+ (propertize (format "%6s" (kubernetes-utils-time-diff-string start current-time))
+ 'face 'magit-dimmed))))))
+ `(nav-prop (:service-name ,name)
+ (copy-prop ,name
+ ,(cond
+ ((member name pending-deletion)
+ `(propertize (face kubernetes-pending-deletion) ,line))
+ ((member name marked-services)
+ `(mark-for-delete ,line))
+ (t
+ line))))))
+
+(kubernetes-ast-define-component service (state service)
+ `(section (,(intern (kubernetes-state-resource-name service)) t)
+ (heading (service-line ,state ,service))
+ (indent
+ (section (details nil)
+ (service-details ,service)
+ (padding)))))
+
+(kubernetes-ast-define-component services-list (state &optional hidden)
+ (-let [(services-response &as &alist 'items services) (kubernetes-state-services state)]
+ `(section (services-container ,hidden)
+ (header-with-count "Services" ,services)
+ (indent
+ (columnar-loading-container ,services ,kubernetes-services--column-heading
+ ,(--map `(service ,state ,it) services)))
+ (padding))))
+
+
+;; Requests and state management
+
+(defun kubernetes-services-refresh (&optional interactive)
+ (unless (kubernetes-process-poll-services-process-live-p)
+ (kubernetes-process-set-poll-services-process
+ (kubernetes-kubectl-get-services kubernetes-props
+ (kubernetes-state)
+ (lambda (response)
+ (kubernetes-state-update-services response)
+ (when interactive
+ (message "Updated services.")))
+ (lambda ()
+ (kubernetes-process-release-poll-services-process))))))
+
+(defun kubernetes-services-delete-marked (state)
+ (let ((names (kubernetes-state-marked-services state)))
+ (dolist (name names)
+ (kubernetes-state-delete-service name)
+ (kubernetes-kubectl-delete-service kubernetes-props state name
+ (lambda (_)
+ (message "Deleting service %s succeeded." name))
+ (lambda (_)
+ (message "Deleting service %s failed" name)
+ (kubernetes-state-mark-service name))))
+ (kubernetes-state-trigger-redraw)))
+
+
+;; Displaying services
+
+(defun kubernetes-services--read-name (state)
+ "Read a service name from the user.
+
+STATE is the current application state.
+
+Update the service state if it not set yet."
+ (-let* (((&alist 'items services)
+ (or (kubernetes-state-services state)
+ (progn
+ (message "Getting services...")
+ (let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-services)))
+ (kubernetes-state-update-services response)
+ response))))
+ (services (append services nil))
+ (names (-map #'kubernetes-state-resource-name services)))
+ (completing-read "Service: " names nil t)))
+
+;;;###autoload
+(defun kubernetes-display-service (service-name state)
+ "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."
+ (interactive (let ((state (kubernetes-state)))
+ (list (kubernetes-services--read-name state) state)))
+ (if-let (service (kubernetes-state-lookup-service service-name state))
+ (select-window
+ (display-buffer
+ (kubernetes-yaml-make-buffer kubernetes-display-service-buffer-name service)))
+ (error "Unknown service: %s" service-name)))
+
+
+(provide 'kubernetes-services)
+
+;;; kubernetes-services.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-services.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-state.el
@@ -0,0 +1,504 @@
+;;; kubernetes-state.el --- Main state for Kubernetes -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'dash)
+(require 'cl-lib)
+(require 'seq)
+(require 'subr-x)
+
+(require 'kubernetes-vars)
+
+
+;;; Main state
+
+(defvar kubernetes-state--current-state nil)
+
+(defun kubernetes-state ()
+ kubernetes-state--current-state)
+
+(defun kubernetes-state-update (action &optional args)
+ (let ((updated (kubernetes-state-next kubernetes-state--current-state action args)))
+ (setq kubernetes-state--current-state updated)))
+
+(defun kubernetes-state-next (state action &optional args)
+ (let ((next (copy-alist state)))
+ (pcase action
+
+ (:update-current-time
+ (setf (alist-get 'current-time next) args))
+ (:update-last-error
+ (setf (alist-get 'last-error next) args))
+ (:update-label-query
+ (setf (alist-get 'label-query next) args))
+ (:update-namespaces
+ (setf (alist-get 'namespaces next) args))
+ (:update-current-namespace
+ (setf (alist-get 'current-namespace next) args))
+ (:update-kubectl-flags
+ (setf (alist-get 'kubectl-flags next) args))
+ (:update-overview-sections
+ (setf (alist-get 'overview-sections next) args))
+
+ (:update-config
+ (setf (alist-get 'config next) args)
+ (unless (alist-get 'current-namespace next)
+ (-when-let ((&alist 'context (&alist 'namespace ns))
+ (kubernetes-state--lookup-current-context args))
+ (setf (alist-get 'current-namespace next) ns))))
+
+ (:unmark-all
+ (setf (alist-get 'marked-configmaps next nil t) nil)
+ (setf (alist-get 'marked-deployments next nil t) nil)
+ (setf (alist-get 'marked-jobs next nil t) nil)
+ (setf (alist-get 'marked-pods next nil t) nil)
+ (setf (alist-get 'marked-secrets next nil t) nil)
+ (setf (alist-get 'marked-services next nil t) nil))
+
+ ;; Pods
+
+ (:mark-pod
+ (let ((cur (alist-get 'marked-pods state)))
+ (setf (alist-get 'marked-pods next)
+ (delete-dups (cons args cur)))))
+ (:unmark-pod
+ (setf (alist-get 'marked-pods next)
+ (remove args (alist-get 'marked-pods next))))
+ (:delete-pod
+ (let ((updated (cons args (alist-get 'pods-pending-deletion state))))
+ (setf (alist-get 'pods-pending-deletion next)
+ (delete-dups updated))))
+ (:update-pods
+ (setf (alist-get 'pods next) args)
+ ;; Prune deleted pods from state.
+ (-let* (((&alist 'items pods) args)
+ (pod-names (seq-map #'kubernetes-state-resource-name (append pods nil))))
+ (setf (alist-get 'marked-pods next)
+ (seq-intersection (alist-get 'marked-pods next)
+ pod-names))
+ (setf (alist-get 'pods-pending-deletion next)
+ (seq-intersection (alist-get 'pods-pending-deletion next)
+ pod-names))))
+
+ ;; Configmaps
+
+ (:mark-configmap
+ (let ((cur (alist-get 'marked-configmaps state)))
+ (setf (alist-get 'marked-configmaps next)
+ (delete-dups (cons args cur)))))
+ (:unmark-configmap
+ (setf (alist-get 'marked-configmaps next)
+ (remove args (alist-get 'marked-configmaps next))))
+ (:delete-configmap
+ (let ((updated (cons args (alist-get 'configmaps-pending-deletion state))))
+ (setf (alist-get 'configmaps-pending-deletion next)
+ (delete-dups updated))))
+ (:update-configmaps
+ (setf (alist-get 'configmaps next) args)
+
+ ;; Prune deleted configmaps from state.
+ (-let* (((&alist 'items configmaps) args)
+ (configmap-names (seq-map #'kubernetes-state-resource-name (append configmaps nil))))
+ (setf (alist-get 'marked-configmaps next)
+ (seq-intersection (alist-get 'marked-configmaps next)
+ configmap-names))
+ (setf (alist-get 'configmaps-pending-deletion next)
+ (seq-intersection (alist-get 'configmaps-pending-deletion next)
+ configmap-names))))
+
+ ;; Secrets
+
+ (:mark-secret
+ (let ((cur (alist-get 'marked-secrets state)))
+ (setf (alist-get 'marked-secrets next)
+ (delete-dups (cons args cur)))))
+ (:unmark-secret
+ (setf (alist-get 'marked-secrets next)
+ (remove args (alist-get 'marked-secrets next))))
+ (:delete-secret
+ (let ((updated (cons args (alist-get 'secrets-pending-deletion state))))
+ (setf (alist-get 'secrets-pending-deletion next)
+ (delete-dups updated))))
+ (:update-secrets
+ (setf (alist-get 'secrets next) args)
+
+ ;; Prune deleted secrets from state.
+ (-let* (((&alist 'items secrets) args)
+ (secret-names (seq-map #'kubernetes-state-resource-name (append secrets nil))))
+ (setf (alist-get 'marked-secrets next)
+ (seq-intersection (alist-get 'marked-secrets next)
+ secret-names))
+ (setf (alist-get 'secrets-pending-deletion next)
+ (seq-intersection (alist-get 'secrets-pending-deletion next)
+ secret-names))))
+
+
+ ;; Services
+
+ (:mark-service
+ (let ((cur (alist-get 'marked-services state)))
+ (setf (alist-get 'marked-services next)
+ (delete-dups (cons args cur)))))
+ (:unmark-service
+ (setf (alist-get 'marked-services next)
+ (remove args (alist-get 'marked-services next))))
+ (:delete-service
+ (let ((updated (cons args (alist-get 'services-pending-deletion state))))
+ (setf (alist-get 'services-pending-deletion next)
+ (delete-dups updated))))
+ (:update-services
+ (setf (alist-get 'services next) args)
+
+ ;; Prune deleted services from state.
+ (-let* (((&alist 'items services) args)
+ (service-names (seq-map #'kubernetes-state-resource-name (append services nil))))
+ (setf (alist-get 'marked-services next)
+ (seq-intersection (alist-get 'marked-services next)
+ service-names))
+ (setf (alist-get 'services-pending-deletion next)
+ (seq-intersection (alist-get 'services-pending-deletion next)
+ service-names))))
+
+ ;; Jobs
+
+ (:mark-job
+ (let ((cur (alist-get 'marked-jobs state)))
+ (setf (alist-get 'marked-jobs next)
+ (delete-dups (cons args cur)))))
+ (:unmark-job
+ (setf (alist-get 'marked-jobs next)
+ (remove args (alist-get 'marked-jobs next))))
+ (:delete-job
+ (let ((updated (cons args (alist-get 'jobs-pending-deletion state))))
+ (setf (alist-get 'jobs-pending-deletion next)
+ (delete-dups updated))))
+ (:update-jobs
+ (setf (alist-get 'jobs next) args)
+
+ (-let* (((&alist 'items jobs) args)
+ (job-names (seq-map #'kubernetes-state-resource-name (append jobs nil))))
+ (setf (alist-get 'marked-jobs next)
+ (seq-intersection (alist-get 'marked-jobs next)
+ job-names))
+ (setf (alist-get 'jobs-pending-deletion next)
+ (seq-intersection (alist-get 'jobs-pending-deletion next)
+ job-names))))
+
+ ;; Deployments
+
+ (:mark-deployment
+ (let ((cur (alist-get 'marked-deployments state)))
+ (setf (alist-get 'marked-deployments next)
+ (delete-dups (cons args cur)))))
+ (:unmark-deployment
+ (setf (alist-get 'marked-deployments next)
+ (remove args (alist-get 'marked-deployments next))))
+ (:delete-deployment
+ (let ((updated (cons args (alist-get 'deployments-pending-deletion state))))
+ (setf (alist-get 'deployments-pending-deletion next)
+ (delete-dups updated))))
+ (:update-deployments
+ (setf (alist-get 'deployments next) args)
+
+ ;; Prune deleted deployments from state.
+ (-let* (((&alist 'items deployments) args)
+ (deployment-names (seq-map #'kubernetes-state-resource-name (append deployments nil))))
+ (setf (alist-get 'marked-deployments next)
+ (seq-intersection (alist-get 'marked-deployments next)
+ deployment-names))
+ (setf (alist-get 'deployments-pending-deletion next)
+ (seq-intersection (alist-get 'deployments-pending-deletion next)
+ deployment-names))))
+
+ (_
+ (error "Unknown action: %s" action)))
+
+ next))
+
+(defun kubernetes-state--lookup-current-context (config)
+ (-let [(&alist 'contexts contexts 'current-context current) config]
+ (--find (equal current (alist-get 'name it)) (append contexts nil))))
+
+(defun kubernetes-state-clear ()
+ (setq kubernetes-state--current-state nil))
+
+
+;; Actions
+
+(defun kubernetes-state-mark-pod (pod-name)
+ (cl-assert (stringp pod-name))
+ (kubernetes-state-update :mark-pod pod-name))
+
+(defun kubernetes-state-unmark-pod (pod-name)
+ (cl-assert (stringp pod-name))
+ (kubernetes-state-update :unmark-pod pod-name))
+
+(defun kubernetes-state-delete-pod (pod-name)
+ (cl-assert (stringp pod-name))
+ (kubernetes-state-update :delete-pod pod-name)
+ (kubernetes-state-update :unmark-pod pod-name))
+
+(defun kubernetes-state-mark-job (job-name)
+ (cl-assert (stringp job-name))
+ (kubernetes-state-update :mark-job job-name))
+
+(defun kubernetes-state-unmark-job (job-name)
+ (cl-assert (stringp job-name))
+ (kubernetes-state-update :unmark-job job-name))
+
+(defun kubernetes-state-delete-job (job-name)
+ (cl-assert (stringp job-name))
+ (kubernetes-state-update :delete-job job-name)
+ (kubernetes-state-update :unmark-job job-name))
+
+(defun kubernetes-state-mark-configmap (configmap-name)
+ (cl-assert (stringp configmap-name))
+ (kubernetes-state-update :mark-configmap configmap-name))
+
+(defun kubernetes-state-unmark-configmap (configmap-name)
+ (cl-assert (stringp configmap-name))
+ (kubernetes-state-update :unmark-configmap configmap-name))
+
+(defun kubernetes-state-delete-configmap (configmap-name)
+ (cl-assert (stringp configmap-name))
+ (kubernetes-state-update :delete-configmap configmap-name)
+ (kubernetes-state-update :unmark-configmap configmap-name))
+
+(defun kubernetes-state-mark-secret (secret-name)
+ (cl-assert (stringp secret-name))
+ (kubernetes-state-update :mark-secret secret-name))
+
+(defun kubernetes-state-unmark-secret (secret-name)
+ (cl-assert (stringp secret-name))
+ (kubernetes-state-update :unmark-secret secret-name))
+
+(defun kubernetes-state-delete-secret (secret-name)
+ (cl-assert (stringp secret-name))
+ (kubernetes-state-update :delete-secret secret-name)
+ (kubernetes-state-update :unmark-secret secret-name))
+
+(defun kubernetes-state-mark-service (service-name)
+ (cl-assert (stringp service-name))
+ (kubernetes-state-update :mark-service service-name))
+
+(defun kubernetes-state-unmark-service (service-name)
+ (cl-assert (stringp service-name))
+ (kubernetes-state-update :unmark-service service-name))
+
+(defun kubernetes-state-delete-service (service-name)
+ (cl-assert (stringp service-name))
+ (kubernetes-state-update :delete-service service-name)
+ (kubernetes-state-update :unmark-service service-name))
+
+(defun kubernetes-state-mark-deployment (deployment-name)
+ (cl-assert (stringp deployment-name))
+ (kubernetes-state-update :mark-deployment deployment-name))
+
+(defun kubernetes-state-unmark-deployment (deployment-name)
+ (cl-assert (stringp deployment-name))
+ (kubernetes-state-update :unmark-deployment deployment-name))
+
+(defun kubernetes-state-delete-deployment (deployment-name)
+ (cl-assert (stringp deployment-name))
+ (kubernetes-state-update :delete-deployment deployment-name)
+ (kubernetes-state-update :unmark-deployment deployment-name))
+
+(defun kubernetes-state-unmark-all ()
+ (kubernetes-state-update :unmark-all))
+
+
+;; State accessors
+
+(defmacro kubernetes-state--define-getter (attr)
+ `(defun ,(intern (format "kubernetes-state-%s" attr)) (state)
+ (alist-get (quote ,attr) state)))
+
+(defmacro kubernetes-state--define-setter (attr arglist &rest forms-before-update)
+ (declare (indent 2))
+ (let ((getter (intern (format "kubernetes-state-%s" attr)))
+ (arg
+ (pcase arglist
+ (`(,x) x)
+ (xs `(list ,@xs)))))
+ `(defun ,(intern (format "kubernetes-state-update-%s" attr)) ,arglist
+ ,@forms-before-update
+ (let ((prev (,getter (kubernetes-state)))
+ (arg ,arg))
+ (kubernetes-state-update ,(intern (format ":update-%s" attr)) ,arg)
+
+ ;; Redraw immediately if this value was previously unset.
+ (unless prev
+ (kubernetes-state-trigger-redraw))
+
+ arg))))
+
+(defmacro kubernetes-state--define-accessors (attr arglist &rest forms-before-update)
+ (declare (indent 2))
+ `(progn
+ (kubernetes-state--define-getter ,attr)
+ (kubernetes-state--define-setter ,attr ,arglist ,@forms-before-update)))
+
+(kubernetes-state--define-accessors current-namespace (namespace)
+ (cl-assert (stringp namespace)))
+
+(kubernetes-state--define-accessors pods (pods)
+ (cl-assert (listp pods)))
+
+(kubernetes-state--define-accessors jobs (jobs)
+ (cl-assert (listp jobs)))
+
+(kubernetes-state--define-accessors configmaps (configmaps)
+ (cl-assert (listp configmaps)))
+
+(kubernetes-state--define-accessors secrets (secrets)
+ (cl-assert (listp secrets)))
+
+(kubernetes-state--define-accessors services (services)
+ (cl-assert (listp services)))
+
+(kubernetes-state--define-accessors deployments (deployments)
+ (cl-assert (listp deployments)))
+
+(kubernetes-state--define-accessors namespaces (namespaces)
+ (cl-assert (listp namespaces)))
+
+(kubernetes-state--define-accessors config (config)
+ (cl-assert (listp config)))
+
+(kubernetes-state--define-accessors label-query (label-name)
+ (cl-assert (stringp label-name)))
+
+(defun kubernetes-state-overview-sections (state)
+ (or (alist-get 'overview-sections state)
+ (let* ((configurations (append kubernetes-overview-custom-views-alist kubernetes-overview-views-alist))
+ (sections (alist-get kubernetes-default-overview-view configurations))
+ (updated (kubernetes-state-update :update-overview-sections sections)))
+ (alist-get 'overview-sections updated))))
+
+(kubernetes-state--define-setter overview-sections (resources)
+ (cl-assert (--all? (member it '(context
+ configmaps
+ overview
+ deployments
+ jobs
+ pods
+ secrets
+ services))
+ resources)))
+
+(defun kubernetes-state-kubectl-flags (state)
+ (or (alist-get 'kubectl-flags state)
+ (let ((updated (kubernetes-state-update :update-kubectl-flags kubernetes-kubectl-flags)))
+ (alist-get 'kubectl-flags updated))))
+
+(kubernetes-state--define-setter kubectl-flags (flags)
+ (cl-assert (listp flags))
+ (cl-assert (-all? #'stringp flags))
+ (setq kubernetes-kubectl-flags flags))
+
+(kubernetes-state--define-getter marked-configmaps)
+(kubernetes-state--define-getter configmaps-pending-deletion)
+
+(kubernetes-state--define-getter marked-jobs)
+(kubernetes-state--define-getter jobs-pending-deletion)
+
+(kubernetes-state--define-getter marked-pods)
+(kubernetes-state--define-getter pods-pending-deletion)
+
+(kubernetes-state--define-getter marked-secrets)
+(kubernetes-state--define-getter secrets-pending-deletion)
+
+(kubernetes-state--define-getter marked-services)
+(kubernetes-state--define-getter services-pending-deletion)
+
+(kubernetes-state--define-getter marked-deployments)
+(kubernetes-state--define-getter deployments-pending-deletion)
+
+(kubernetes-state--define-getter last-error)
+
+(defun kubernetes-state-update-last-error (message command time)
+ (cl-assert (stringp message))
+ (cl-assert (stringp command))
+ (cl-assert time)
+ (cl-assert (listp time))
+ (cl-assert (-all? #'integerp time))
+ (let ((arg `((message . ,message)
+ (command . ,command)
+ (time ., time))))
+ (kubernetes-state-update :update-last-error arg)
+ arg))
+
+;; No update function is provided. The time is updated internally before the
+;; redrawing hook is run.
+(kubernetes-state--define-getter current-time)
+
+
+;; Convenience functions.
+
+(defmacro kubernetes-state-define-named-lookup (resource state-key)
+ "Define `kubernetes-state-lookup-RESOURCE' for looking up an item by name.
+
+RESOURCE is the name of the resource.
+
+STATE-KEY is the key to look up an item in the state."
+ (let* ((ident (symbol-name resource))
+ (docstring
+ (format "Look up a %s by name in the current state.
+
+%s-NAME is the name of the %s to search for.
+
+STATE is the current application state.
+
+If lookup succeeds, return the alist representation of the resource.
+If lookup fails, return nil."
+ ident (upcase ident) ident)))
+
+ `(defun ,(intern (format "kubernetes-state-lookup-%s" resource)) (name state)
+ ,docstring
+ (-let [(&alist ',state-key (&alist 'items items)) state]
+ (seq-find (lambda (it) (equal (kubernetes-state-resource-name it) name))
+ items)))))
+
+(kubernetes-state-define-named-lookup configmap configmaps)
+(kubernetes-state-define-named-lookup deployment deployments)
+(kubernetes-state-define-named-lookup job jobs)
+(kubernetes-state-define-named-lookup namespace namespaces)
+(kubernetes-state-define-named-lookup pod pods)
+(kubernetes-state-define-named-lookup secret secrets)
+(kubernetes-state-define-named-lookup service services)
+
+(defun kubernetes-state-resource-name (resource)
+ "Get the name of RESOURCE from its metadata.
+
+RESOURCE is the parsed representation an API resource, such a
+pod, secret, configmap, etc."
+ (-let [(&alist 'metadata (&alist 'name name)) resource]
+ name))
+
+(defun kubernetes-state-resource-label (resource)
+ "Get the label of RESOURCE from its metadata.
+
+RESOURCE is the parsed representation an API resource, such a
+pod, secret, configmap, etc."
+ (-let [(&alist 'metadata (&alist 'labels (&alist 'name label))) resource]
+ label))
+
+(defun kubernetes-state-current-context (state)
+ (when-let (config (kubernetes-state-config state))
+ (kubernetes-state--lookup-current-context config)))
+
+(defun kubernetes-state-clear-error-if-stale (error-display-time)
+ (-when-let ((&alist 'time err-time) (kubernetes-state-last-error (kubernetes-state)))
+ (when (< error-display-time
+ (- (time-to-seconds) (time-to-seconds err-time)))
+ (kubernetes-state-update :update-last-error nil))))
+
+(defun kubernetes-state-trigger-redraw ()
+ (kubernetes-state-update :update-current-time (current-time))
+ (kubernetes-state-clear-error-if-stale kubernetes-minimum-error-display-time)
+ (run-hooks 'kubernetes-redraw-hook))
+
+
+(provide 'kubernetes-state)
+
+;;; kubernetes-state.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-state.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-timers.el
@@ -0,0 +1,43 @@
+;;; kubernetes-timers.el --- Internal timers. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'subr-x)
+(require 'kubernetes-state)
+(require 'kubernetes-vars)
+
+;; Timer vars
+
+(defvar kubernetes-timers--poll-timer nil
+ "Background timer used to poll for updates.
+
+This is used to regularly synchronise local state with Kubernetes.")
+
+(defvar kubernetes-timers--redraw-timer nil
+ "Background timer used to trigger buffer redrawing.
+
+This is used to display the current state.")
+
+
+;; Timer management
+
+(defun kubernetes-timers-initialize-timers ()
+ (unless kubernetes-timers--redraw-timer
+ (setq kubernetes-timers--redraw-timer (run-with-timer 0 kubernetes-redraw-frequency #'kubernetes-state-trigger-redraw)))
+ (unless kubernetes-timers--poll-timer
+ (setq kubernetes-timers--poll-timer (run-with-timer 0 kubernetes-poll-frequency
+ (lambda ()
+ (run-hooks 'kubernetes-poll-hook))))))
+
+(defun kubernetes-timers-kill-timers ()
+ (when-let (timer kubernetes-timers--redraw-timer)
+ (cancel-timer timer))
+ (when-let (timer kubernetes-timers--poll-timer)
+ (cancel-timer timer))
+ (setq kubernetes-timers--redraw-timer nil)
+ (setq kubernetes-timers--poll-timer nil))
+
+
+(provide 'kubernetes-timers)
+
+;;; kubernetes-timers.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-timers.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-utils.el
@@ -0,0 +1,181 @@
+;;; kubernetes-utils.el --- Common utilities. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'dash)
+(require 'subr-x)
+(require 'term)
+
+(require 'kubernetes-ast)
+(require 'kubernetes-kubectl)
+(require 'kubernetes-props)
+(require 'kubernetes-state)
+(require 'kubernetes-timers)
+(require 'kubernetes-vars)
+
+(autoload 'org-read-date "org")
+
+(defun kubernetes-utils-read-pod-name (state)
+ "Read a pod name from the user.
+
+STATE is the current application state.
+
+Update the pod state if it not set yet."
+ (-let* (((&alist 'items pods)
+ (or (kubernetes-state-pods state)
+ (progn
+ (message "Getting pods...")
+ (let ((response (kubernetes-kubectl-await-on-async kubernetes-props state #'kubernetes-kubectl-get-pods)))
+ (kubernetes-state-update-pods response)
+ response))))
+ (pods (append pods nil))
+ (names (-map #'kubernetes-state-resource-name pods)))
+ (completing-read "Pod: " names nil t)))
+
+(defun kubernetes-utils-read-iso-datetime (&rest _)
+ (let* ((date (org-read-date nil t))
+ (tz (format-time-string "%z" date)))
+ (concat
+ (format-time-string "%Y-%m-%dT%H:%M:%S" date)
+ (replace-regexp-in-string (rx (group (? (any "+-")) digit digit)
+ (group digit digit))
+ "\\1:\\2"
+ tz))))
+
+(defun kubernetes-utils-read-time-value (&rest _)
+ "Read a relative time value in the style accepted by kubectl. E.g. 20s, 3h, 5m."
+ (let (result)
+ (while (null result)
+ (let ((input (read-string "Time value (e.g. 20s): ")))
+ (if (string-match-p (rx bol (* space) (+ digit) (* space) (any "smh") (* space) eol)
+ input)
+ (setq result input)
+ (message "Invalid time value")
+ (sit-for 1))))
+ result))
+
+(defun kubernetes-utils-maybe-pod-name-at-point ()
+ (pcase (get-text-property (point) 'kubernetes-nav)
+ (`(:pod-name ,value)
+ value)))
+
+(defun kubernetes-utils-ellipsize (s threshold)
+ (if (> (length s) threshold)
+ (concat (substring s 0 (1- threshold)) "…")
+ s))
+
+(defun kubernetes-utils-parse-utc-timestamp (timestamp)
+ "Parse TIMESTAMP string from the API into the representation used by Emacs."
+ (let ((parsed (parse-time-string (replace-regexp-in-string "Z" "" (replace-regexp-in-string "T" " " timestamp)))))
+ (setf (nth 8 parsed) 0)
+ parsed))
+
+(defun kubernetes-utils-time-diff-string (start now)
+ "Find the interval between START and NOW, and return a string of the coarsest unit."
+ (let ((diff (time-to-seconds (time-subtract now start))))
+ (car (split-string (format-seconds "%yy,%dd,%hh,%mm,%ss%z" diff) ","))))
+
+(defun kubernetes-utils-kill-buffer (proc-buf &rest _)
+ (if-let (win (get-buffer-window proc-buf))
+ (quit-window t win)
+ (kill-buffer proc-buf)))
+
+(defun kubernetes-utils-make-cleanup-fn (buf)
+ "Make a function to add to `kill-buffer-hook' for a Kubernetes buffer.
+
+BUF is the buffer used to display a Kubernetes feature. A
+reference to it is needed to determine which buffers remain.
+
+The function will terminate polling when the last Kubernetes
+buffer is killed."
+ (lambda ()
+ (let* ((bufs (-keep #'get-buffer (list kubernetes-label-query-buffer-name
+ kubernetes-overview-buffer-name)))
+ (more-buffers (remove buf bufs)))
+ (unless more-buffers
+ (dolist (b bufs)
+ (with-current-buffer b
+ (kubernetes-state-clear)))
+ (kubernetes-process-kill-polling-processes)
+ (kubernetes-timers-kill-timers)))))
+
+(defun kubernetes-utils-term-buffer-start (bufname command args)
+ ;; Kill existing process.
+ (when-let ((existing (get-buffer bufname))
+ (proc (get-buffer-process existing)))
+ (kubernetes-process-kill-quietly proc))
+
+ (let ((buf (get-buffer-create bufname)))
+ (with-current-buffer buf
+ (erase-buffer)
+ (buffer-disable-undo)
+ (term-mode)
+ (goto-char (point-min))
+ (let ((time-str (format "Session started at %s" (substring (current-time-string) 0 19)))
+ (command-str (format "%s %s" command (string-join args " "))))
+ (kubernetes-ast-eval
+ `((line ,(propertize time-str 'face 'magit-dimmed))
+ (padding)
+ (line ,(propertize command-str 'face 'magit-dimmed))
+ (padding))))
+
+ (term-exec (current-buffer) "kuberenetes-term" command nil args)
+ (let ((proc (get-buffer-process (current-buffer))))
+ (set-process-query-on-exit-flag proc nil)
+ (term-char-mode)
+ (add-hook 'kill-buffer-hook (lambda ()
+ (when-let (win (get-buffer-window buf))
+ (quit-window nil win)))
+ nil t)))
+
+ buf))
+
+(defun kubernetes-utils-process-buffer-start (bufname setup-fn command args &optional process-filter)
+ (let ((buf (get-buffer-create bufname)))
+ (buffer-disable-undo buf)
+
+ (with-current-buffer buf
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (funcall setup-fn)
+ (let ((time-str (format "Process started at %s" (substring (current-time-string) 0 19)))
+ (command-str (format "%s %s" command (string-join args " "))))
+ (kubernetes-ast-eval
+ `((line ,(propertize time-str 'face 'magit-dimmed))
+ (padding)
+ (line ,(propertize command-str 'face 'magit-dimmed))
+ (padding))))))
+
+ (let ((proc (apply #'start-process "kubernetes-exec" buf command args)))
+ (when process-filter
+ (set-process-filter proc process-filter))
+ (set-process-query-on-exit-flag proc nil))
+ buf))
+
+(defun kubernetes-utils-overview-buffer-selected-p ()
+ (equal (current-buffer) (get-buffer kubernetes-overview-buffer-name)))
+
+(defmacro kubernetes-utils--save-window-state (&rest body)
+ "Restore window state after executing BODY.
+
+This is useful if the buffer is erased and repopulated in BODY,
+in which case `save-excursion' is insufficient to restore the
+window state."
+ `(let ((pos (point))
+ (col (current-column))
+ (window-start-line (window-start))
+ (inhibit-redisplay t))
+ (save-excursion
+ ,@body)
+ (goto-char pos)
+ (move-to-column col)
+ (set-window-start (selected-window) window-start-line)))
+
+(defun kubernetes-utils-up-to-existing-dir (dir)
+ (while (not (file-directory-p dir))
+ (setq dir (file-name-directory (directory-file-name dir))))
+ dir)
+
+(provide 'kubernetes-utils)
+
+;;; kubernetes-utils.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-utils.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-vars.el
@@ -0,0 +1,197 @@
+;;; kubernetes-vars.el --- Customizable interface for Kubernetes package. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(defgroup kubernetes nil
+ "Emacs porcelain for Kubernetes."
+ :group 'tools
+ :prefix "kubernetes-")
+
+(defcustom kubernetes-kubectl-executable "kubectl"
+ "The kubectl command used for Kubernetes commands."
+ :group 'kubernetes
+ :type 'string)
+
+(defconst kubernetes-overview-views-alist
+ '((overview . (context overview))
+ (configmaps . (context configmaps))
+ (deployments . (context deployments))
+ (jobs . (context jobs))
+ (pods . (context pods))
+ (secrets . (context secrets))
+ (services . (context services)))
+ "Enumerates the different views that can be displayed in the overview.
+
+Each element is a cons-cell of the form (SYMBOL . LIST), where
+SYMBOL is a name for the view, and LIST is a list of resource
+types that should be displayed.")
+
+(defcustom kubernetes-overview-custom-views-alist nil
+ "Enumerates the different views that can be displayed in the overview.
+
+Each element is a cons-cell of the form (SYMBOL . LIST), where
+SYMBOL is a name for the view, and LIST is a list of resource
+types that should be displayed."
+ :group 'kubernetes
+ :type '(alist :key-type symbol
+ :value-type (set (const context)
+ (const configmaps)
+ (const deployments)
+ (const overview)
+ (const pods)
+ (const secrets)
+ (const services))))
+
+(defcustom kubernetes-default-overview-view 'overview
+ "The view to use when first opening the overview.
+
+It should be one of the keys defined in
+`kubernetes-overview-views-alist' or
+`kubernetes-overview-custom-views-alist'."
+ :group 'kubernetes
+ :type 'symbol)
+
+(defcustom kubernetes-commands-display-buffer-select t
+ "Whether to select Kubernetes buffers automatically."
+ :group 'kubernetes
+ :type 'boolean)
+
+(defcustom kubernetes-commands-display-buffer-function 'kubernetes-commands-display-buffer-fullframe
+ "The function used display a Kubernetes buffer.
+
+The function must take a single argument, which is the buffer to display."
+ :group 'kubernetes
+ :type '(radio (function-item kubernetes-commands-display-buffer-fullframe)
+ (function-item display-buffer)
+ (function :tag "Function")))
+
+(defcustom kubernetes-pod-restart-warning-threshold 5
+ "The threshold for pod restarts above which a pod is highlighted."
+ :group 'kubernetes
+ :type 'number)
+
+(defcustom kubernetes-poll-frequency 5
+ "The frequency at which to poll Kubernetes for changes."
+ :group 'kubernetes
+ :type 'integer)
+
+(defcustom kubernetes-redraw-frequency 5
+ "The buffer redraw frequency in seconds.
+
+This is the frequency at which Kubernetes buffers will be redrawn
+to match the current state. This variable should be tuned to
+balance interface stuttering with update frequency."
+ :group 'kubernetes
+ :type 'integer)
+
+(defcustom kubernetes-json-mode 'javascript-mode
+ "The mode to use when rendering pretty-printed JSON."
+ :group 'kubernetes
+ :type 'function)
+
+(defcustom kubernetes-default-exec-command "bash"
+ "The default command to use when exec'ing into a pod's container."
+ :group 'kubernetes
+ :type 'string)
+
+(defcustom kubernetes-clean-up-interactive-exec-buffers t
+ "If non-nil, automatically kill interactive exec buffers on process exit."
+ :group 'kubernetes
+ :type 'boolean)
+
+(defcustom kubernetes-minimum-error-display-time 10
+ "Minimum time in seconds for which errors will be displayed in overview buffer."
+ :group 'kubernetes
+ :type 'integer)
+
+(defcustom kubernetes-kubectl-flags nil
+ "A list of extra commandline flags to pass to kubectl.
+
+It is a list, where each element is assumed to be a flag of the
+form \"--flag=value\" or \"-flag\"."
+ :type '(repeat (string :tag "Argument"))
+ :group 'kubernetes)
+
+
+(defface kubernetes-context-name
+ '((((class color) (background light)) :foreground "SkyBlue4")
+ (((class color) (background dark)) :foreground "LightSkyBlue1"))
+ "Face for context names in report buffers."
+ :group 'kubernetes)
+
+(defface kubernetes-json-key
+ '((((class color) (background light)) :foreground "grey30" :weight bold)
+ (((class color) (background dark)) :foreground "grey80" :weight bold))
+ "Face for keys in pretty-printed parsed JSON."
+ :group 'kubernetes)
+
+(defface kubernetes-progress-indicator
+ '((t :inherit shadow))
+ "Face for progress indicators."
+ :group 'kubernetes)
+
+(defface kubernetes-pending-deletion
+ '((t :inherit shadow :strike-through t))
+ "Face for pods awaiting deletion."
+ :group 'kubernetes)
+
+(defface kubernetes-delete-mark
+ '((t :inherit error))
+ "Face for deletion mark indicators."
+ :group 'kubernetes)
+
+(defface kubernetes-selector
+ '((t :inherit magit-branch-remote))
+ "Face for labels used as selectors."
+ :group 'kubernetes)
+
+(defface kubernetes-namespace
+ '((t :inherit magit-tag))
+ "Face for namespace references."
+ :group 'kubernetes)
+
+
+(defconst kubernetes-display-pods-buffer-name "*kubernetes pods*")
+
+(defconst kubernetes-display-config-buffer-name "*kubernetes config*")
+
+(defconst kubernetes-display-deployment-buffer-name "*kubernetes deployment*")
+
+(defconst kubernetes-display-job-buffer-name "*kubernetes job*")
+
+(defconst kubernetes-display-configmap-buffer-name "*kubernetes configmap*")
+
+(defconst kubernetes-display-service-buffer-name "*kubernetes service*")
+
+(defconst kubernetes-display-configmaps-buffer-name "*kubernetes configmaps*")
+
+(defconst kubernetes-display-namespace-buffer-name "*kubernetes namespace*")
+
+(defconst kubernetes-display-secret-buffer-name "*kubernetes secret*")
+
+(defconst kubernetes-display-secrets-buffer-name "*kubernetes secrets*")
+
+(defconst kubernetes-overview-buffer-name "*kubernetes overview*")
+
+(defconst kubernetes-log-line-buffer-name "*log line*")
+
+(defconst kubernetes-logs-buffer-name "*kubernetes logs*")
+
+(defconst kubernetes-pod-buffer-name "*kubernetes pod*")
+
+(defconst kubernetes-exec-buffer-name "*kubernetes exec*")
+
+(defconst kubernetes-label-query-buffer-name "*kubernetes-label-query*")
+
+
+(defvar kubernetes-poll-hook nil
+ "Hook run every time polling should occur.")
+
+(defvar kubernetes-redraw-hook nil
+ "Hook run every time redrawing should occur.")
+
+
+
+(provide 'kubernetes-vars)
+
+;;; kubernetes-vars.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-vars.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-yaml.el
@@ -0,0 +1,79 @@
+;;; kubernetes-yaml.el --- YAML pretty-printing. -*- lexical-binding: t; -*-
+;;; Commentary:
+;;; Code:
+
+(require 'dash)
+(require 'subr-x)
+
+(require 'kubernetes-ast)
+(require 'kubernetes-modes)
+
+
+;; Compile parsed JSON into an AST representation for rendering.
+
+(defun kubernetes-yaml--render-helper (json)
+ (pcase json
+ ;; Literals
+
+ ('nil "null")
+ ('t "true")
+ (:json-false "false")
+ ((pred stringp) json)
+ ((pred numberp) (number-to-string json))
+ ((pred symbolp) (symbol-name json))
+
+ ;; Lists
+
+ ((pred vectorp)
+ `(list ,@(seq-map (lambda (it)
+ `(section (item nil) ,(kubernetes-yaml--render-helper it)))
+ json)))
+
+ ;; Objects
+
+ ((pred listp)
+ (seq-map (-lambda ((k . v))
+ (let ((k (kubernetes-yaml--render-helper k))
+ (v (kubernetes-yaml--render-helper v)))
+ `(section (object-kvp nil)
+ ,(cond
+ ;; Indent multiline strings.
+ ((and (stringp v) (string-match-p "\n" (string-trim-right v)))
+ `(copy-prop ,v
+ (heading ,(concat (propertize (format "%s:" k) 'face 'magit-section-heading) " |-"))
+ (indent ,@(--map `(line ,it) (split-string (string-trim-right v) "\n")))))
+
+ ((stringp v)
+ `(key-value 0 ,k ,v))
+
+ (t
+ `((heading ,(concat (propertize (format "%s:" k) 'face 'magit-section-heading) " "))
+ (indent ,v)))))))
+ json))
+
+ (_
+ (error "Don't know how to render %s" json))))
+
+(defun kubernetes-yaml-render (json)
+ "Process some parsed JSON into a YAML AST for rendering."
+ `(section (json-root nil)
+ ,(kubernetes-yaml--render-helper json)
+ (padding)))
+
+
+;; Drawing utilites
+
+(defun kubernetes-yaml-make-buffer (bufname parsed-json)
+ (let ((buf (get-buffer-create bufname)))
+ (with-current-buffer buf
+ (kubernetes-display-thing-mode)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (kubernetes-ast-eval (kubernetes-yaml-render parsed-json))
+ (goto-char (point-min))))
+ buf))
+
+
+(provide 'kubernetes-yaml)
+
+;;; kubernetes-yaml.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes-yaml.elc
Binary file
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes.el
@@ -0,0 +1,35 @@
+;;; kubernetes.el --- Magit-like porcelain for Kubernetes. -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Chris Barrett
+
+;; Author: Chris Barrett <chris+emacs@walrus.cool>
+
+;; Version: 0.11.3
+
+;; Package-Requires: ((emacs "25.1") (dash "2.12.0") (magit "2.8.0"))
+
+;; This program 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.
+
+;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'kubernetes-commands)
+(require 'kubernetes-labels)
+(require 'kubernetes-logs)
+(require 'kubernetes-overview)
+
+(provide 'kubernetes)
+
+;;; kubernetes.el ends here
.emacs.d/elpa/kubernetes-20170523.1517/kubernetes.elc
Binary file
.emacs.d/emacs.el
@@ -207,6 +207,12 @@
:ensure t
:init (dired-quick-sort-setup))
+(use-package dired-collapse
+ :ensure t
+ :init
+ :config
+ (dired-collapse-mode))
+
(use-package diminish
:ensure t
:demand t
@@ -2093,6 +2099,10 @@ that directory."
ad-return-value)
ad-return-value)))
+(use-package kubernetes
+ :ensure t
+ :commands (kubernetes-overview))
+
;; The folder is by default $HOME/.emacs.d/provided
(setq user-emacs-provided-directory (concat user-emacs-directory "provided/"))
;; Regexp to find org files in the folder
.emacs.d/emacs.org
@@ -561,6 +561,16 @@
:init (dired-quick-sort-setup))
#+END_SRC
+ And use =dired-collapse= to have a « à -la-git » dired buffer.
+
+ #+BEGIN_SRC emacs-lisp
+ (use-package dired-collapse
+ :ensure t
+ :init
+ :config
+ (dired-collapse-mode))
+ #+END_SRC
+
** Diminish minor modes from the mode line
Now that we have made sure we have installed use-package, we will make
@@ -3551,6 +3561,16 @@
ad-return-value)))
#+END_SRC
+* Kubernetes
+
+ Trying some things out with k8s 👼
+
+ #+BEGIN_SRC emacs-lisp
+ (use-package kubernetes
+ :ensure t
+ :commands (kubernetes-overview))
+ #+END_SRC
+
* Provided configuration
I'm managing my configurations using [[https://github.com/RichiH/vcsh][vcsh]] and [[http://myrepos.branchable.com/][myrepos]], like [[https://github.com/vdemeester/vcsh-home#how-it-is-supposed-to-work][that]]. I have a lot