Skip to content

Commit

Permalink
Merge branch 'master' into alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleywang1 authored Feb 1, 2021
2 parents b1bedc0 + dff5f99 commit 94b7bbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 4 additions & 0 deletions changelog/v0.17.2/kubeconfig-loader-check-recommended.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/skv2/issues/205
description: Add recommended kubeconfig directory path to kubeconfig loader loading rules.
20 changes: 5 additions & 15 deletions pkg/multicluster/kubeconfig/loader.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
package kubeconfig

import (
"fmt"
"os"
"os/user"
"path"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

// Fetch ClientConfig. If kubeConfigPath is not specified, retrieve the kubeconfig from environment in which this is invoked.
// Override the API Server URL and current context if specified.
// Copied and modified from https://github.com/kubernetes-sigs/controller-runtime/blob/cb7f85860a8cde7259b35bb84af1fdcb02c098f2/pkg/client/config/config.go#L135
func GetClientConfigWithContext(kubeConfigPath, kubeContext, apiServerUrl string) (clientcmd.ClientConfig, error) {

// default loading rules checks for KUBECONFIG env var
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
// also check recommended default kubeconfig file locations
loadingRules.Precedence = append(loadingRules.Precedence, clientcmd.RecommendedHomeFile)

// explicit path overrides all loading rules, will error if not found
if kubeConfigPath != "" {
loadingRules.ExplicitPath = kubeConfigPath
} else {
// Fetch kubeconfig from environment in which this is invoked
if _, ok := os.LookupEnv("HOME"); !ok {
u, err := user.Current()
if err != nil {
return nil, fmt.Errorf("could not get current user: %v", err)
}
loadingRules.Precedence = append(loadingRules.Precedence, path.Join(u.HomeDir, clientcmd.RecommendedHomeDir, clientcmd.RecommendedFileName))
}
}

overrides := &clientcmd.ConfigOverrides{}
Expand Down

0 comments on commit 94b7bbf

Please sign in to comment.