kubernetes.lisp 1000 B

1234567891011121314151617181920212223242526272829
  1. (in-package :stumpwm)
  2. (defvar *kubernetes-current-cluster* "")
  3. (defun kubernetes-current-cluster ()
  4. (string-trim '(#\Newline)
  5. (run-shell-command
  6. (join
  7. (list "yq" "--raw-output" "'.\"current-context\"'"
  8. (concat (getenv "HOME") "/.kube/config")))
  9. t)))
  10. (defcommand kubernetes-update-current-cluster () ()
  11. (setq *kubernetes-current-cluster* (kubernetes-current-cluster)))
  12. (defcommand kubernetes-update-current-cluster-inotify () ()
  13. (run-shell-command
  14. (join
  15. (list "ls" "-1" (concat (getenv "HOME") "/.kube/config")
  16. "|" "entr" "-n" "-r" "bash" "-c"
  17. (format nil "~s" "echo '(kubernetes-update-current-cluster)' | stumpish -e eval")))))
  18. (defun kubectl-current-context (cluster &optional color)
  19. "Returns a string representing the current kubectl context."
  20. (if color
  21. (cond (t
  22. (format nil "kubernetes: ~a" cluster)))
  23. (format nil "kubernetes: ~a" cluster)))