Last active
February 25, 2022 14:50
-
-
Save linktohack/85528b1a6d62f0b69a720a72770d8348 to your computer and use it in GitHub Desktop.
KUBEL with Lens config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar helm-source-lens-kubeconfigs nil "Lens kubeconfigs source") | |
(defun my/kubel-with-lens-configs (&optional kubeconfigs-dir) | |
"Launch kubel with Lens configs. | |
Require `yq' (a wrapper of `jq' for `yaml') in your path." | |
(interactive) | |
(unless kubeconfigs-dir | |
(setq kubeconfigs-dir "~/Library/Application Support/Lens/kubeconfigs")) | |
(unless helm-source-lens-kubeconfigs | |
(setq helm-source-lens-kubeconfigs | |
(let* ((dir (expand-file-name kubeconfigs-dir)) | |
(command (format "pushd \"%s\" | |
for i in * | |
do echo \"$(cat \"$i\" | yq -r '.clusters[0].name')|$i\" | |
done" dir))) | |
(thread-last | |
command | |
(shell-command-to-string) | |
(string-trim) | |
((lambda (str) (split-string str "\n"))) | |
(seq-map (lambda (c) (split-string c "|"))))))) | |
(helm :sources (helm-build-sync-source "Lens kubeconfigs" | |
:candidates helm-source-lens-kubeconfigs | |
:action #'(lambda (cand) | |
(kubel-set-kubectl-config-file | |
(format "%s/%s" | |
(expand-file-name kubeconfigs-dir) | |
(car cand))) | |
(kubel-set-context) | |
(kubel-set-namespace))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment