From 9de16f2c451b993c1af6e8dd15bfd0bfe151d562 Mon Sep 17 00:00:00 2001
From: rithu leena john <rithujohn191@gmail.com>
Date: Tue, 25 Oct 2016 11:51:59 -0700
Subject: [PATCH] storage/kubernetes: set CurrentContext when the Kubeconfig
 file contains only one context

---
 storage/kubernetes/client.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/storage/kubernetes/client.go b/storage/kubernetes/client.go
index bfdc9151..e700a3f4 100644
--- a/storage/kubernetes/client.go
+++ b/storage/kubernetes/client.go
@@ -348,7 +348,11 @@ func inClusterConfig() (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace
 
 func currentContext(config *k8sapi.Config) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, ns string, err error) {
 	if config.CurrentContext == "" {
-		return cluster, user, "", errors.New("kubeconfig has no current context")
+		if len(config.Contexts) == 1 {
+			config.CurrentContext = config.Contexts[0].Name
+		} else {
+			return cluster, user, "", errors.New("kubeconfig has no current context")
+		}
 	}
 	context, ok := func() (k8sapi.Context, bool) {
 		for _, namedContext := range config.Contexts {
-- 
GitLab