func NewKubeClientConfig(kubeconfigPath, context, namespace string) clientcmd.ClientConfig {
	rules := clientcmd.NewDefaultClientConfigLoadingRules()
	rules.DefaultClientConfig = &clientcmd.DefaultClientConfig
	if kubeconfigPath != "" {
		rules.ExplicitPath = kubeconfigPath
	}
	overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
	if context != "" {
		overrides.CurrentContext = context
	}
	if namespace != "" {
		overrides.Context.Namespace = namespace
	}
	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
}
NewKubeClientConfig return a kube client config that will by default use an
in cluster client config or, if not available or overridden, an external client
config using the default client behavior used also by kubectl.
package util
import (
	"fmt"
	"os"
	"k8s.io/client-go/tools/clientcmd"
)
const (
	KubePodName = "POD_NAME"
	KubeResourcePrefix = "stolon-cluster"
	KubeClusterLabel = "stolon-cluster"
	KubeClusterDataAnnotation = "stolon-clusterdata"
	KubeStatusAnnnotation     = "stolon-status"
)
func PodName() (string, error) {
	podName := os.Getenv(KubePodName)
	if len(podName) == 0 {
		return "", fmt.Errorf("missing required env variable %q", KubePodName)
	}
	return podName, nil
}