diff --git a/pkg/models/openpitrix/attachments.go b/pkg/models/openpitrix/attachments.go index c9a0ef55d..ac2ac2018 100644 --- a/pkg/models/openpitrix/attachments.go +++ b/pkg/models/openpitrix/attachments.go @@ -15,6 +15,7 @@ package openpitrix import ( "bytes" + "github.com/go-openapi/strfmt" "k8s.io/klog" diff --git a/pkg/simple/client/k8s/options.go b/pkg/simple/client/k8s/options.go index 642e5284d..f4d97bd43 100644 --- a/pkg/simple/client/k8s/options.go +++ b/pkg/simple/client/k8s/options.go @@ -18,6 +18,7 @@ package k8s import ( "os" + "os/user" "path" "k8s.io/client-go/util/homedir" @@ -54,8 +55,16 @@ func NewKubernetesOptions() (option *KubernetesOptions) { } // make it be easier for those who wants to run api-server locally - userHomeConfig := path.Join(homedir.HomeDir(), ".kube/config") - if _, err := os.Stat(userHomeConfig); !os.IsNotExist(err) { + homePath := homedir.HomeDir() + if homePath == "" { + // try os/user.HomeDir when $HOME is unset. + if u, err := user.Current(); err == nil { + homePath = u.HomeDir + } + } + + userHomeConfig := path.Join(homePath, ".kube/config") + if _, err := os.Stat(userHomeConfig); err == nil { option.KubeConfig = userHomeConfig } return