1
0
mirror of https://github.com/docker/cli.git synced 2025-08-29 00:47:54 +03:00
Files
cli/kubernetes/config.go
2018-05-09 17:30:36 +02:00

27 lines
729 B
Go

package kubernetes
import (
"os"
"path/filepath"
"github.com/docker/docker/pkg/homedir"
"k8s.io/client-go/tools/clientcmd"
)
// NewKubernetesConfig resolves the path to the desired Kubernetes configuration file based on
// the KUBECONFIG environment variable and command line flags.
func NewKubernetesConfig(configPath string) clientcmd.ClientConfig {
kubeConfig := configPath
if kubeConfig == "" {
if config := os.Getenv("KUBECONFIG"); config != "" {
kubeConfig = config
} else {
kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
}
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfig},
&clientcmd.ConfigOverrides{})
}