<p>I want to use Kubernetes Go client to execute various actions in a cluster.
I am loading my local <code>kubeconfig</code> which contains multiple clusters and contexts. The default context is <code>prod</code> and one of the config values I want to override is the <code>CurrentContext</code> </p>

<pre><code>    clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        &amp;clientcmd.ClientConfigLoadingRules{ExplicitPath: "/Users/me/.kube/config"},
        &amp;clientcmd.ConfigOverrides{
            CurrentContext: "stage",
        })

    rawConfig, _ := clientConfig.RawConfig()
    log.Printf(rawConfig.CurrentContext) // outputs "prod" instead of "stage"
</code></pre>

<p>When I inspect <code>RawConfig()</code> the current context is still "prod" instead of "stage".
Why does the config override not work?</p>

<p>Also how does the override for AuthInfo etc. work? The override accepts only a single <code>AuthInfo</code> whereas the configuration contains a map of <code>AuthInfo</code> etc.</p>

<p>GitHub related issue <a href="https://github.com/kubernetes/client-go/issues/735" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/issues/735</a></p>

Hedge
<blockquote>
  <p>Why does the config override not work?</p>
</blockquote>

<p>according to</p>

<p><a href="https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L57-L58" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L57-L58</a></p>

<pre class="lang-golang prettyprint-override"><code>// ClientConfig is used to make it easy to get an api server client
type ClientConfig interface {
    // RawConfig returns the merged result of all overrides
    RawConfig() (clientcmdapi.Config, error)
</code></pre>

<p><code>RawConfig</code> should return config with overrides, but it really doesn't</p>

<p><a href="https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L122-L124" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L122-L124</a></p>

<pre class="lang-golang prettyprint-override"><code>func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) {
    return config.config, nil
}
</code></pre>

<p>just return config without overrides. You could see a possible solution here in my patch</p>

<p><a href="https://github.com/vvelikodny/kubernetes-client-go/pull/1/files" rel="nofollow noreferrer">https://github.com/vvelikodny/kubernetes-client-go/pull/1/files</a></p>

<blockquote>
  <p>Also how does the override for AuthInfo etc. work? The override accepts only a single AuthInfo whereas the configuration contains a map of AuthInfo etc.</p>
</blockquote>

<p>override only AuthInfo with the key of username which presented in context.AuthInfo (string). </p>

<p><a href="https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L424-L437" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L424-L437</a></p>

<p><a href="https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L388-L394" rel="nofollow noreferrer">https://github.com/kubernetes/client-go/blob/a432bd9ba7da427ae0a38a6889d72136bce4c4ea/tools/clientcmd/client_config.go#L388-L394</a></p>

<pre class="lang-golang prettyprint-override"><code>// getAuthInfoName returns a string containing the current authinfo name for the current context,
// and a boolean indicating  whether the default authInfo name is overwritten by a user-set flag, or
// left as its default value
func (config *DirectClientConfig) getAuthInfoName() (string, bool) {
    if len(config.overrides.Context.AuthInfo) != 0 {
        return config.overrides.Context.AuthInfo, true
    }
    context, _ := config.getContext()
    return context.AuthInfo, false
}
</code></pre>
