How can I get the current namespace of an out-of-cluster Go Kubernetes client using the client-go library?
I am using this code example: https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go for out-cluster client.
Here is an extract of my KUBECONFIG which might help in clarifying:
- context:
cluster: kind-kind
namespace: mynamespace
user: kind-kind
name: kind-kind
current-context: kind-kind
I'd like to find an easy way to retrieve mynamespace.
Thanks to @rick-rackow answer and comment, I was able to improve my understanding of the kubeconfig API, so here is a simple solution which works fine for me: