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 bd43cdb..24e51ff 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." + (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. 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 + (mapcar (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.")