Kubecontext on next does not correctly pull the namespace when no AUTHINFO set for the cluster.
Not being a kubernetes user myself, I'm not sure how to go about addressing this.
Any thoughts from our kubecontext experts? @jtaylor32
I will look into this. This makes sense -- @derekbassett if you could give me some context around what sort of Kubernetes config problems you're running into I'd love to try and replicate this so I can fix it!
@derekbassett - Just a ping, here, on @jtaylor32's question, above!
My situation has several of clusters not having SSL or AUTHINFO turned on.
if I were to do a kubectl config get-contexts the command would print out something like this:
CURRENT | NAME | CLUSTER | AUTHINFO | NAMESPACE
----------|-------|----------------------|------------------------|----------------------
|| dev-int| dev-int|
*| minikube| minikube| minikube
|| sit-qa | sit-qa || mynamespace
In the case of minikube this is the default settings after it is initial installed.
My initial thought was to use
local k8s_namespace=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $NF}')
As that would pick up the last value normally the namespace but in the case of minikube in the case of minikube or any other cluster with no namespace defined it would print out either AUTHINFO or CLUSTER not optimal but is what I've been using for a while in my own branch.
I'm not sure without a Kubernetes Client change it is even possible to consistently get the current namespace.
Let me know if that answers your question or if you have any other ideas.
Ahh I see what you mean. 99.9% of the time I am always in namespaces other than default. I do get the same error you are saying but my prompt would look something like minikube/ and it just doesn't have a namespace after. Maybe we can detect if namespace is not set to default to default. What do you think @derekbassett?
@derekbassett - Just a ping on @jtaylor32's question, above!
I investigated this a small bit. Without a change to Kubectl I don't see a way to reliably do this. When the namespace is default it just leaves the column empty. If the authentication is unset then it will also leave the namespace unset. Most of the clusters I work with lack authentication. Would you be up for generating a PR to Kubectl adding the ability to add namespace as a header as a command line flag?
@derekbassett I would be up for it - I don't have the bandwidth in the interim to do that but I would be open to potentially seeing if we can get a PR for this fix into the tool. I apologize I usually have authentication and change namespaces quite often in our environments. If there is anything else you see potentially on the prompt side of thing we can get that into this branch of next.
We might be able to get away with just the context names for un-authenticated clusters. I don't see any other way around this.
I know this a little stale at this point I will have a new fix for this in the next couple days when I can find the time. I already have the fix setup locally. I appreciate the patience @derekbassett and @bhilburn. FWIW this should would with whatever kind of contexts and namespace names you have regardless.
I totally get it. If you get the change on a branch send me the branch name and I will pull it out down and try it out for you!
Sounds great thanks man. I'll keep y'all updated in the next coming days - I might be able to get some time in the AM.
@derekbassett Just pushed a new PR let me know how those changes look for you.
I just pulled in your changes, I had a question about what kubectl version supported -o=jsonpath but otherwise it looks great.
Excited to get @captjt's PR merged! Just left a comment about failing unittests =)
Closed by @derekbassett's PR #661