From e189ac4fc2559c26410c5a4c4de16bfa9a03b5d3 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Wed, 5 Jun 2019 12:56:30 +0800 Subject: [PATCH] Fallback to get user home directory from env (#1203) --- pkg/fission-cli/util/util.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/fission-cli/util/util.go b/pkg/fission-cli/util/util.go index c2a0c9cc..a293e61d 100644 --- a/pkg/fission-cli/util/util.go +++ b/pkg/fission-cli/util/util.go @@ -122,12 +122,18 @@ func GetKubernetesClient() (*restclient.Config, *kubernetes.Clientset) { kubeConfigPath := os.Getenv("KUBECONFIG") if len(kubeConfigPath) == 0 { + var homeDir string usr, err := user.Current() if err != nil { - log.Fatal(fmt.Sprintf("Could not get the current users directory: %s", err)) + // In case that user.Current() may be unable to work under some circumstances and return errors like + // "user: Current not implemented on darwin/amd64" due to cross-compilation problem. (https://github.com/golang/go/issues/6376). + // Instead of doing fatal here, we fallback to get home directory from the environment $HOME. + log.Warn(fmt.Sprintf("Could not get the current user's directory (%s), fallback to get it from env $HOME", err)) + homeDir = os.Getenv("HOME") + } else { + homeDir = usr.HomeDir } - - kubeConfigPath = filepath.Join(usr.HomeDir, ".kube", "config") + kubeConfigPath = filepath.Join(homeDir, ".kube", "config") if _, err := os.Stat(kubeConfigPath); os.IsNotExist(err) { log.Fatal("Couldn't find kubeconfig file. " +