-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I get the namespace of the context I'm using? #1359
Comments
This seems to work cfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfigPath}, nil)
rCfg, err := cfg.RawConfig()
if err != nil {
fmt.Printf("error getting raw config: %v\n", err)
os.Exit(1)
}
namespace := rCfg.Contexts[rCfg.CurrentContext].Namespace
kubeConfig, err := cfg.ClientConfig() (ie opening up BuildConfigFromFlags and making it do return the internal config object instead of just the ClientConfig) |
you can also even more simply call:
but that one won't be empty, it defaults to |
This all works fine, thanks. I also wonder what the override flag is for. I'll get to that at some point. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to use client-go v0.24.0 to talk to my v1.24.x Kubernetes cluster. I can hack the code in the "out-of-cluster-client-configuration" sample to hardcode the namespace, and that works, but I really need to use the namespace specified in the "namespace" property of the context from the ~/.kube/config . I've been looking through the "Config" type returned from "BuildConfigFromFlags", but I can't see any indication in that of the namespace for the context. I find it hard to believe that I'd have to get this info by separately parsing the config file. That is certainly doable, but I would think it should be available through a more direct interface.
The text was updated successfully, but these errors were encountered: