ahmetb / kubectx

Faster way to switch between clusters and namespaces in kubectl
https://kubectx.dev
Apache License 2.0
17.66k stars 1.26k forks source link

kubie and kubens mixed cause kubeconfig syntax error #384

Closed lagunary closed 1 year ago

lagunary commented 1 year ago

Hello Guys,

I use your stuff all the time, it ia great stuff. Thanks for it.

I have a little bug. Although it is a little, it is so irritating. Im using kubie with kubectx and kubens (at the most of time to use kube for set context) When I start a new terminal with 'kubie ctx' and select a cluster, the proper kube config will be generatred into the /tmp/kubie-.yaml At this time if I use kubens and select a namespace, the kube config namespace field will be:

❯ kgp
error: error loading config file "/tmp/kubie-configRcB26D.yaml": yaml: cannot decode !!str `kube-node-lease` as a !!null
❯ cat /tmp/kubie-configRcB26D.yaml | grep namespace
        namespace: !!null kube-node-lease

There is a !!null in the namespace field. After you delete this 6chars ('!!null ') it will be proper and from this time it is working properly. Both kubie, kubens. For native kubernetes clusters this problem is not showed. The problem is showed only for OpenShift cluters. (It is magic :)) More intersting facts: kubens cannot do this error without kubie kubie cannot do this error without kubens

I would like to ask you how can I localize the source of the error? Do you have any idea what cause this error? Is it possible to use 'default' instead of '~' character at namespace value field?

Thanks in advance. BR, Viktor

ahmetb commented 1 year ago

Which implementation of Kubectx do you use (bash script or go binary)?

lagunary commented 1 year ago

go binary

ahmetb commented 1 year ago

I am quite confused as I havent seen this format before. If you can paste some kubeconfig snippets that can repro the problem, I am happy to take a look.

lagunary commented 1 year ago

My main kubeconfig (default location ~/.kube/config) contains 7 clusters. I cant share the datas, but simple multicluster setup, with openshift clusters and vanilla kubernetes. The problem is showing only first time when move into kubie context. I need to patch file manually and after it everything is fine. In my opinion, this problematic part could be an 'if', 'loop', 'func' at start, where some checking is processing, and one of it has a null return. it should be near there where you try to make the current context. it is just based on logic, i havent checked the code. Can you give me advise how can make kubie more verbose logging?

Thanks, Viktor

ahmetb commented 1 year ago

You can always redact the kubeconfig file values and share its structure.

I'm not sure if your problem is with kubie or kubens, maybe file it at kubie repo as the error does not seem from kubens?

lagunary commented 1 year ago

it cannot be reproduced without kubens and vica versa.

when kubie starts and make the "new terminal" with different kubeconfig. It is proper.

Is it possible that kubens cannot grant the whole structure when get ~(default) namespace char. Im going to ask them.

lagunary commented 1 year ago

Hello,

@ahmetb

I found the exact location of the error: Kubie generates kubeconfig file with this

namespace: ~

Your kubens code is not tolerating this, it will be fullfilled with this (variable comes from choosen namespace, in this example default):

namespace: !!null default

The problem could be here or here

Would you help me about it? Thanks, Viktor

ahmetb commented 1 year ago

As far as I know neither of those values are known to kubectl. Not sure why I should be fixing this. Can elaborate what they mean?

lagunary commented 1 year ago

I've just suggest to "fix" this, cause honestly it is not a bug in your application. If kubens can handle this kind of behaviour, your app could be more compatible with other tools, maybe it will be more popular (if it counts). If you are not sure about fixing, I can check it also, and if I'll find something solution (modify code to tolerate '~' this character at namespace) I can contact you, and you can decide to merge or not.

ahmetb commented 1 year ago

Are you sure kubectl tolerates ~ ? I don't use kubie so I don't know what it means. I don't necessarily need code contributions, trying to understand.

lagunary commented 1 year ago

Im not sure about it, but, Ive tried with my kubeconfig, and it works. It could be a fallback, I dont know cause Google hasnt got any relevant information about this. kubectl config use-context that-one-has-symbol-at-namespace-field is working for me with '~'

ahmetb commented 1 year ago

Also I see kubie is an alternative to this tool. Not sure why you're using both at the same time. :)