mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-01 23:39:41 +00:00
fix: take KUBECONFIG
env variable into consideration (#340)
Before, the default value set for the `--kubeconfig` flag prevented the `KUBECONFIG` env variable to be ever taken into consideration. This behavior has now been fixed. If `--kubeconfig` flag is set, it takes precedence over the `KUBECONFIG` env variable. fixes #331 Signed-off-by: Patrick Pichler <git@patrickpichler.dev> Co-authored-by: Patrick Pichler <git@patrickpichler.dev>
This commit is contained in:
@@ -44,8 +44,14 @@ func NewClient(kubecontext string, kubeconfig string) (*Client, error) {
|
||||
var config *rest.Config
|
||||
config, err := rest.InClusterConfig()
|
||||
if err != nil {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
|
||||
if kubeconfig != "" {
|
||||
loadingRules.ExplicitPath = kubeconfig
|
||||
}
|
||||
|
||||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig},
|
||||
loadingRules,
|
||||
&clientcmd.ConfigOverrides{
|
||||
CurrentContext: kubecontext,
|
||||
})
|
||||
|
Reference in New Issue
Block a user