github.com/docker/compose-on-kubernetes@v0.5.0/api/config.go (about)

     1  package apis
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/docker/docker/pkg/homedir"
     8  	"k8s.io/client-go/tools/clientcmd"
     9  )
    10  
    11  // NewKubernetesConfig resolves the path to the desired Kubernetes configuration file based on
    12  // the KUBECONFIG environment variable and command line flags.
    13  func NewKubernetesConfig(configPath string) clientcmd.ClientConfig {
    14  	kubeConfig := configPath
    15  	if kubeConfig == "" {
    16  		if config := os.Getenv("KUBECONFIG"); config != "" {
    17  			kubeConfig = config
    18  		} else {
    19  			kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
    20  		}
    21  	}
    22  
    23  	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
    24  		&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfig},
    25  		&clientcmd.ConfigOverrides{})
    26  }