Skip to content

Commit

Permalink
Print a progress reporter when loading kubeconfig changes
Browse files Browse the repository at this point in the history
Now that kubeconfig loading is performed asynchronously, users are no longer
blocked on the loading process. The trade-off now is that users have no idea of
a) when kubeconfig loading is taking place (and the results of their other
`kele-` operations are potentially stale) and b) when it has completed (and
their `kele-` operations are now guaranteed to be up-to-date and accurate).

To remedy that opacity, we use a [progress reporter][1] to print a conventional
"doing thing..." message when the subroutine starts, and a "doing thing...done"
message when it concludes.

[1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Progress.html
  • Loading branch information
jinnovation committed Jan 6, 2023
1 parent 369521d commit a951c2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
7 changes: 5 additions & 2 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ versioning][semver].

### Added

- The primary update loop reading from kubeconfig and listening for changes on
it is now asynchronous and therefore non-blocking!
- Kubeconfig file watching is now asynchronous and therefore non-blocking!
- Kubeconfig file watching now prints a [progress report] denoting when changes
were detected (and thus reading has begun asynchronously) and when reading has
completed

### Fixed

Expand Down Expand Up @@ -50,3 +52,4 @@ future enhancements.
- Added ability to switch namespaces for any given context

[1]: https://github.com/ahmetb/kubectx
[progress report]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Progress.html
31 changes: 17 additions & 14 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,23 @@ configuration, e.g. via `kubectl config'.")
This is done asynchronously. To wait on the results, pass the
retval into `async-wait'."
(async-start `(lambda ()
;; TODO: How to just do all of these in one fell swoop?
(add-to-list 'load-path (file-name-directory ,(locate-library "yaml")))
(add-to-list 'load-path (file-name-directory ,(locate-library "f")))
(add-to-list 'load-path (file-name-directory ,(locate-library "s")))
(add-to-list 'load-path (file-name-directory ,(locate-library "dash")))
(require 'yaml)
(require 'f)
,(async-inject-variables "kele-kubeconfig-path")
(yaml-parse-string (f-read kele-kubeconfig-path)
:object-type 'alist
:sequence-type 'list))
(lambda (config)
(setq kele--kubeconfig config))))
(let* ((progress-reporter (make-progress-reporter "Pulling kubeconfig contents..."))
(func-complete (lambda (config)
(setq kele--kubeconfig config)
(progress-reporter-done progress-reporter))))
(async-start `(lambda ()
;; TODO: How to just do all of these in one fell swoop?
(add-to-list 'load-path (file-name-directory ,(locate-library "yaml")))
(add-to-list 'load-path (file-name-directory ,(locate-library "f")))
(add-to-list 'load-path (file-name-directory ,(locate-library "s")))
(add-to-list 'load-path (file-name-directory ,(locate-library "dash")))
(require 'yaml)
(require 'f)
,(async-inject-variables "kele-kubeconfig-path")
(yaml-parse-string (f-read kele-kubeconfig-path)
:object-type 'alist
:sequence-type 'list))
func-complete)))

(defun kele-current-context-name ()
"Get the current context name.
Expand Down

0 comments on commit a951c2c

Please sign in to comment.