From d0ca82d624ada613ea0822d1ce7cd0409ec39033 Mon Sep 17 00:00:00 2001
From: Matt McEuen <madgin@madgin.net>
Date: Fri, 17 Jan 2020 17:00:11 -0600
Subject: [PATCH] Fix config clusters index in CurrentContextCluster()

Config.Clusters should be indexed only by "simple" cluster names
(without _ephemeral or _target postfixes).  This fixes an index
that indexed by the "full" cluster name defined in the kubeconfig,
in some cases resulting in a nil pointer dereference.

Change-Id: Ic7a4b46419354d5755ccea58ff73c5fbbc4d9658
---
 pkg/config/config.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pkg/config/config.go b/pkg/config/config.go
index 3c571e209..711ceeeeb 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -568,8 +568,10 @@ func (c *Config) CurrentContextCluster() (*Cluster, error) {
 	if err != nil {
 		return nil, err
 	}
+	clusterName := NewClusterComplexName()
+	clusterName.FromName(currentContext.KubeContext().Cluster)
 
-	return c.Clusters[currentContext.KubeContext().Cluster].ClusterTypes[currentContext.ClusterType()], nil
+	return c.Clusters[clusterName.ClusterName()].ClusterTypes[currentContext.ClusterType()], nil
 }
 
 func (c *Config) CurrentContextAuthInfo() (*AuthInfo, error) {