title: How to get namespace from current-context set in .kube/config
body: <p>I am trying to get programmatically in Go, the namespace of the current-context from ~/.kube/config.</p>
  
  <p>So far what I tried is from these modules:</p>
  
  <pre><code>    "k8s.io/client-go/tools/clientcmd"
      "k8s.io/client-go/kubernetes"
  
  
  
  kubeconfig := filepath.Join(
       os.Getenv("HOME"), ".kube", "config",
  )
  config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
  if err != nil {
      log.Fatal(err)
  }
  
  fmt.Printf("Namespace: %s\n", config.Namespace())
  clientset, err := kubernetes.NewForConfig(config)
  if err != nil {
      log.Fatal(err)
  }
  </code></pre>
  
  <p>But still no clue if clientset can give me the namespace I am looking for. From this thread:
  <a href="https://stackoverflow.com/questions/53283347/how-to-get-current-namespace-of-an-in-cluster-go-kubernetes-client">How to get current namespace of an in-cluster go Kubernetes client</a></p>
  
  <p>It says something of this to be done:
  kubeconfig.Namespace()</p>