Merge pull request #634 from rithujohn191/kubeconfig_context

storage/kubernetes: set CurrentContext when the Kubeconfig file contains only one context
This commit is contained in:
Eric Chiang 2016-10-25 14:57:57 -07:00 committed by GitHub
commit 101a2bc22a

View File

@ -346,8 +346,12 @@ func inClusterConfig() (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace
func currentContext(config *k8sapi.Config) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, ns string, err error) { func currentContext(config *k8sapi.Config) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, ns string, err error) {
if config.CurrentContext == "" { if config.CurrentContext == "" {
if len(config.Contexts) == 1 {
config.CurrentContext = config.Contexts[0].Name
} else {
return cluster, user, "", errors.New("kubeconfig has no current context") return cluster, user, "", errors.New("kubeconfig has no current context")
} }
}
context, ok := func() (k8sapi.Context, bool) { context, ok := func() (k8sapi.Context, bool) {
for _, namedContext := range config.Contexts { for _, namedContext := range config.Contexts {
if namedContext.Name == config.CurrentContext { if namedContext.Name == config.CurrentContext {