From c83812144ca594e2a5dff0437cdf1a3c2fe9ed92 Mon Sep 17 00:00:00 2001 From: Morlay Date: Wed, 8 Sep 2021 17:48:39 +0800 Subject: [PATCH] util: support load Colon-separated KUBECONFIG Signed-off-by: Morlay --- commands/util.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/commands/util.go b/commands/util.go index 330d8073..fbb89f7c 100644 --- a/commands/util.go +++ b/commands/util.go @@ -246,14 +246,15 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N func configFromContext(endpointName string, s ctxstore.Reader) (clientcmd.ClientConfig, error) { if strings.HasPrefix(endpointName, "kubernetes://") { u, _ := url.Parse(endpointName) - if kubeconfig := u.Query().Get("kubeconfig"); kubeconfig != "" { - clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}, - &clientcmd.ConfigOverrides{}, - ) - return clientConfig, nil + _ = os.Setenv(clientcmd.RecommendedConfigPathEnvVar, kubeconfig) + } + rules := clientcmd.NewDefaultClientConfigLoadingRules() + apiConfig, err := rules.Load() + if err != nil { + return nil, err } + return clientcmd.NewDefaultClientConfig(*apiConfig, &clientcmd.ConfigOverrides{}), nil } return kubernetes.ConfigFromContext(endpointName, s) }