mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-24 07:14:15 +00:00
Support KUBECONFIG environment variable.
If KUBECONFIG environment variable is set, use it. Otherwise default to ~/.kube/config
This commit is contained in:
parent
6e279bfca5
commit
cef0e01cf6
@ -10,6 +10,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/client-go/util/homedir"
|
"k8s.io/client-go/util/homedir"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewFromInCluster(errOut chan error) (*Resolver, error) {
|
func NewFromInCluster(errOut chan error) (*Resolver, error) {
|
||||||
@ -26,9 +27,14 @@ func NewFromInCluster(errOut chan error) (*Resolver, error) {
|
|||||||
|
|
||||||
func NewFromOutOfCluster(kubeConfigPath string, errOut chan error) (*Resolver, error) {
|
func NewFromOutOfCluster(kubeConfigPath string, errOut chan error) (*Resolver, error) {
|
||||||
if kubeConfigPath == "" {
|
if kubeConfigPath == "" {
|
||||||
|
env := os.Getenv("KUBECONFIG")
|
||||||
|
if env != "" {
|
||||||
|
kubeConfigPath = env
|
||||||
|
} else {
|
||||||
home := homedir.HomeDir()
|
home := homedir.HomeDir()
|
||||||
kubeConfigPath = filepath.Join(home, ".kube", "config")
|
kubeConfigPath = filepath.Join(home, ".kube", "config")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configPathList := filepath.SplitList(kubeConfigPath)
|
configPathList := filepath.SplitList(kubeConfigPath)
|
||||||
configLoadingRules := &clientcmd.ClientConfigLoadingRules{}
|
configLoadingRules := &clientcmd.ClientConfigLoadingRules{}
|
||||||
|
Loading…
Reference in New Issue
Block a user