'How to get current k8s context name using client-go

I am trying to get / print the name of my current kubernetes context as it is configured in ~/.kube/config using client-go

I hava managed to authenticate and get the *rest.Config object

    config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        &clientcmd.ClientConfigLoadingRules{ExplicitPath: pathToKubeConfig},
        &clientcmd.ConfigOverrides{
            CurrentContext: "",
        }).ClientConfig()

but I don't see any relevant fields in the config struct.

Note that despite the fact I am passing an empty string ("") in the ConfigOverrides the config object returned provides me a kubernetes.Clientset that is based on my current kubectl context.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source