<p>I am trying to get / print the name of my current <code>kubernetes</code> context as it is configured in <code>~/.kube/config</code> using <code>client-go</code></p>
<p>I hava managed to authenticate and get the <code>*rest.Config</code> object</p>
<pre class="lang-golang prettyprint-override"><code>    config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        &amp;clientcmd.ClientConfigLoadingRules{ExplicitPath: pathToKubeConfig},
        &amp;clientcmd.ConfigOverrides{
            CurrentContext: &quot;&quot;,
        }).ClientConfig()
</code></pre>
<p>but I don't see any relevant fields in the <code>config</code> struct.</p>
<p>Note that despite the fact I am passing an empty string (<code>&quot;&quot;</code>) in the <code>ConfigOverrides</code> the <code>config</code> object returned provides me a <code>kubernetes.Clientset</code> that is based on my current <code>kubectl</code> context.</p>

pkaramol
<p>The function <code>ClientConfig()</code> returns the Kubernetes API client config, so it has no information about your config file.</p>
<p>To get the current context, you need to call <code>RawConfig()</code>, then there is a field called <code>CurrentContext</code>.</p>
<p>The following code should work.</p>
<pre class="lang-golang prettyprint-override"><code>    config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        &amp;clientcmd.ClientConfigLoadingRules{ExplicitPath: pathToKubeConfig},
        &amp;clientcmd.ConfigOverrides{
            CurrentContext: &quot;&quot;,
        }).RawConfig()
    currentContext := config.CurrentContext
</code></pre>
