-
Notifications
You must be signed in to change notification settings - Fork 49
cli/cmd: rename --kubeconfig flag to --kubeconfig-file #602
Conversation
4133c67
to
6f16108
Compare
d39d68b
to
ad712a7
Compare
It turns out, I introduced some other bugs to the implementation, so I decided to write tests for it, even though they are not great. |
cli/cmd/root.go
Outdated
"Path to kubeconfig file, taken from the asset dir if not given or from KUBECONFIG "+ | ||
"environment variable and finally falls back to ~/.kube/config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can take this opportunity to improve the text a bit.
"Path to kubeconfig file, taken from the asset dir if not given or from KUBECONFIG "+ | |
"environment variable and finally falls back to ~/.kube/config") | |
`Path to a kubeconfig file. If empty, the following precedence order is used: 1. cluster asset dir when a lokocfg file is present in the current directory 2. KUBECONFIG environment variable 3. "~/.kube/config"`) |
cli/cmd/utils.go
Outdated
// flag or environment variable. Then the asset directory of the cluster is searched | ||
// and finally the global default value is used. This cannot be done in Viper | ||
// because we need the other values from Viper to find the asset directory. | ||
// getKubeconfig finds the kubeconfig to be used. The preference is following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// getKubeconfig finds the kubeconfig to be used. The preference is following: | |
// getKubeconfig finds the kubeconfig to be used. The precedence is the following: |
cli/cmd/utils.go
Outdated
// - --kubeconfig-file flag OR KUBECONFIG_FILE environent variable. | ||
// - Asset directory from cluster configuration. | ||
// - KUBECONFIG environment variable. | ||
// - ~/.kube/config path, which is kubectl default one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// - ~/.kube/config path, which is kubectl default one. | |
// - ~/.kube/config path, which is the default for kubectl. |
cli/cmd/utils.go
Outdated
// assetsKubeconfigPath reads the lokocfg configuration and returns | ||
// path to kubeconfig file in it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// assetsKubeconfigPath reads the lokocfg configuration and returns | |
// path to kubeconfig file in it. | |
// assetsKubeconfigPath reads the lokocfg configuration and returns | |
// the kubeconfig path defined in it. |
@@ -0,0 +1,184 @@ | |||
// Copyright 2020 The Lokomotive Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a test where both the KUBECONFIG flag is set and the lokocfg file is present to make sure it takes the file defined in the lokocfg. This is the most dangerous case IMO.
Even after installing the component by setting the Consider the the simplest scenario :
IMO, we should just have a flag Can we perhaps use Extensions (not sure how extensions is used, I've never seen it in a kubeconfig file) in the kubeconfig file to specify the additional cluster information as managed by Lokomotive. If the |
I agree with Imran, that having this env variable is not really desired. Unfortunately, this is a side effect of the cobra. I'm not sure if we can disable env variable reading for just one flag. |
Just as a reminder, my main focus for this PR is fixing the following case (which happened to me twice with bad consequences):
I agree the Regarding falling back to On the one hand Since falling back to |
This also renames environment variable equivalent of old flag, which was KUBECONFIG to KUBECONFIG_FILE. This is to avoid prefering KUBECONFIG environment variable over cluster configuration, which is happening right now, as we treat --kubeconfig flag and KUBECONFIG environment variable as the same thing, implicitly via 'viper.AutomaticEnv()' call. The order of selecting kubeconfig file to use should be following: 1. --kubeconfig-file flag OR KUBECONFIG_FILE environment variable 2. cluster configuration in working directory 3. KUBECONFIG environment variable (currently not implemented) 4. ~/.kube/config file Part of #595. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
After renaming --kubeconfig flag to --kubeconfig-file, we lost ability to use kubeconfig file defined by KUBECONFIG environment variable for installing components. This commit adds back this functionality and improves the code of getKubeconfig() function a bit. Closes #595 Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
Otherwise linter complains. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
So resulting code is much easier to understand. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
ad712a7
to
0687e1e
Compare
Addressed my review since @invidian is out. |
0687e1e
to
ab7638a
Compare
To make sure we do it right, as otherwise it might be destructive. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
ab7638a
to
7470a24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR renames
--kubeconfig
flag to--kubeconfig-file
to avoid automatic reading ofKUBECONFIG
environment variable by viper and adds explicit read ofKUBECONFIG
variable after cluster configuration in the hierarchy, when selectingkubeconfig
file to use.For the time being, there is no tests for this patch, as testing that is not trivial to implement (involves creating lokocfg configuration file in temporary directory, testing private method, and testing viper flags parsing.
Closes #595.