Skip to content

Commit

Permalink
Merge pull request #92 from girishramnani/os_sepr
Browse files Browse the repository at this point in the history
Use of OS independent file path separator in KubeConfig exists util function
  • Loading branch information
maysunfaisal committed Jun 11, 2021
2 parents 179c407 + 5a9a5ff commit 0867af2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
kvalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/util/homedir"
"k8s.io/klog"
)

Expand Down Expand Up @@ -1071,8 +1072,13 @@ func CheckKubeConfigExist() bool {
if os.Getenv("KUBECONFIG") != "" {
kubeconfig = os.Getenv("KUBECONFIG")
} else {
home, _ := os.UserHomeDir()
kubeconfig = fmt.Sprintf("%s/.kube/config", home)
if home := homedir.HomeDir(); home != "" {
kubeconfig = filepath.Join(home, ".kube", "config")
klog.V(4).Infof("using default kubeconfig path %s", kubeconfig)
} else {
klog.V(4).Infof("no KUBECONFIG provided and cannot fallback to default")
return false
}
}

if CheckPathExists(kubeconfig) {
Expand Down

0 comments on commit 0867af2

Please sign in to comment.