From 3594a99b50abb1172d5f3144ba69ee6d02ade2dc Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Thu, 1 Dec 2022 12:31:17 +0530 Subject: [PATCH 1/5] Environment variable is propagated now --- kubel.el | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kubel.el b/kubel.el index bd43cdb..9c402cc 100644 --- a/kubel.el +++ b/kubel.el @@ -212,6 +212,11 @@ :type '(file :must-match t) :group 'kubel) +(defcustom kubel-env-variables nil + "The environment variables that needs to be propagated in kubel session." + :type '(list string) + :group 'kubel) + (defconst kubel--process-buffer "*kubel-process*" "Kubel process buffer name.") @@ -256,14 +261,20 @@ CMD is the kubectl command as a list." (kubel--append-to-process-buffer (format "[%s]\ncommand: %s" process-name str-cmd)))) +(defun kubel--env-values () + "Utility function to propgate kubernetes related environment variables." + (map 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) + (defun kubel--exec-to-string (cmd) "Replace \"shell-command-to-string\" to log to process buffer. CMD is the command string to run." (kubel--log-command "kubectl-command" cmd) - (with-output-to-string - (with-current-buffer standard-output - (shell-command cmd t "*kubel stderr*")))) + (let ((env-values (kubel--env-values))) + (with-output-to-string + (with-current-buffer standard-output + (map 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) + (shell-command cmd t "*kubel stderr*"))))) (defvar kubel-namespace "default" "Current namespace.") From e0659d9ad5a06bdc2fe7a6c99c58b1e7ee931d0b Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 2 Dec 2022 09:34:01 +0530 Subject: [PATCH 2/5] Use cl-map instead of map --- kubel.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubel.el b/kubel.el index 9c402cc..6a3ebe7 100644 --- a/kubel.el +++ b/kubel.el @@ -263,7 +263,7 @@ CMD is the kubectl command as a list." (defun kubel--env-values () "Utility function to propgate kubernetes related environment variables." - (map 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) + (cl-map 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) (defun kubel--exec-to-string (cmd) "Replace \"shell-command-to-string\" to log to process buffer. From 87a16a9f3a49121977c17830bfaef55a7f1b4e8a Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 2 Dec 2022 09:36:40 +0530 Subject: [PATCH 3/5] Use cl-map --- kubel.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubel.el b/kubel.el index 6a3ebe7..46ca85b 100644 --- a/kubel.el +++ b/kubel.el @@ -273,7 +273,7 @@ CMD is the command string to run." (let ((env-values (kubel--env-values))) (with-output-to-string (with-current-buffer standard-output - (map 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) + (cl-map 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) (shell-command cmd t "*kubel stderr*"))))) (defvar kubel-namespace "default" From 039c9e16f4140efc9ffe69d98de40c08d0f79a18 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Tue, 6 Dec 2022 08:54:26 +0530 Subject: [PATCH 4/5] Change to mapcar and improve documentation --- README.md | 8 ++++++++ kubel.el | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7898941..1890fb4 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,14 @@ Alternatively, you can hit `E` to then select the resource type and the resource - auto - default, use `kubectl auth can-i list namespace` to determine if we can list namespaces - on - always assume we can list namespaces - off - always assume we cannot list namespaces +- If you want to propagate environment variables, you can use + customize on `kubel-env-variables` to propagate it. This is useful + for scenarios where you are using something like [envrc](https://github.com/purcell/envrc) to + manage multiple clusters: + +``` emacs-lisp +(customize-set-variable 'kubel-env-variables '("KUBECONFIG" "AWS_ACCESS_KEY_ID" "AWS_SECRET_ACCESS_KEY")) +``` ## Releases diff --git a/kubel.el b/kubel.el index 46ca85b..2afee87 100644 --- a/kubel.el +++ b/kubel.el @@ -263,7 +263,7 @@ CMD is the kubectl command as a list." (defun kubel--env-values () "Utility function to propgate kubernetes related environment variables." - (cl-map 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) + (mapcar 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) (defun kubel--exec-to-string (cmd) "Replace \"shell-command-to-string\" to log to process buffer. @@ -273,7 +273,7 @@ CMD is the command string to run." (let ((env-values (kubel--env-values))) (with-output-to-string (with-current-buffer standard-output - (cl-map 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) + (mapcar 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) (shell-command cmd t "*kubel stderr*"))))) (defvar kubel-namespace "default" From 1ca068379c1786b2a4045081a07676e6e6fac54b Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Tue, 6 Dec 2022 09:11:19 +0530 Subject: [PATCH 5/5] Fix mapcar --- kubel.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kubel.el b/kubel.el index 2afee87..24e51ff 100644 --- a/kubel.el +++ b/kubel.el @@ -263,7 +263,7 @@ CMD is the kubectl command as a list." (defun kubel--env-values () "Utility function to propgate kubernetes related environment variables." - (mapcar 'list (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) + (mapcar (lambda(env) `(:name ,env :value ,(getenv env))) kubel-env-variables)) (defun kubel--exec-to-string (cmd) "Replace \"shell-command-to-string\" to log to process buffer. @@ -273,7 +273,7 @@ CMD is the command string to run." (let ((env-values (kubel--env-values))) (with-output-to-string (with-current-buffer standard-output - (mapcar 'list (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) + (mapcar (lambda (env) (setenv (plist-get env ':name) (plist-get env ':value))) env-values) (shell-command cmd t "*kubel stderr*"))))) (defvar kubel-namespace "default"