k8s-inventory
k8s-inventory copied to clipboard
Automatically use KUBECONFIG env var
What would you like to be added:
Currently, kai will use ~/.kube/config
to connect to the cluster, even if the KUBECONFIG
environment variable points to a different file. This makes it necessary to manually specify the -k $KUBECONFIG
option when calling kai, creating the risk of inadvertently running kai against a different cluster than kubectl.
I would propose that kai should automatically use the kubeconfig file pointed to by the KUBECONFIG
enviroment variable if it is set, otherwise attempt to use the current default of ~/.kube/config
as a fallback to be consistent with other k8s tools.
Why is this needed:
Some users keep multiple separate kubeconfig files and switch between them by pointing the KUBECONFIG
environment variable at the active config file. Kubectl and friends automatically pick up the active config from the environment, so having kai do the same would increase consistency and reduce the surprise factor for the user.
Additional context:
Hello @AdrianoKF! Thanks for submitting the request. I have passed it along to PM for review
@AdrianoKF @zburstein just wanna check on something real quick here!
The environment variable to set the kubeconfig path should take precedence, but want to make sure we're setting the right one. In order for KAI to prefer a different path besides the home directory's kubeconfig, it looks in the following places:
-
KAI_KUBECONFIG_PATH
-
kai.yaml
kubeconfig path override:kubeconfig.path
-
kai.yaml
direct kube config (i.e. translating the actual kubeconfig into the kai.yaml file) -
~.kube/config
So, as you mentioned, kai
is not respecting the KUBECONFIG
env var directly, but it would respect KAI_KUBECONFIG_PATH
. It seems that you're suggesting that the KUBECONFIG
env var is used more commonly by k8s operators and that we should interpret that as well. Perhaps we could add it between options 3 and 4 above in terms of order of precedence? Would that satisfy the feature request as it's laid out in your comment?
@dakaneye Yes, I like adding it between 3 and 4. That'll allow for it to work as expected.