c-bata / kube-prompt

An interactive kubernetes client featuring auto-complete.
MIT License
1.79k stars 134 forks source link

When using a context with a namespace that is not `default`, pod completion is for default namespace #13

Open cgilling opened 6 years ago

cgilling commented 6 years ago

First off, thanks for writing this tool, it looks like it should be pretty helpful. Excited to start using it more.

This is for version 1.0.1:

As you can see below my context is registered to use the seu namespace by default, but the completions are from the default namespace. But then when the actual command is run it uses the proper namespace, and therefore can't find my auto completed pod.

>>> get pods --all-namespaces
NAMESPACE     NAME                                                                READY     STATUS             RESTARTS   AGE
...
default       canopy-2965694291-f5f6c                                             1/1       Running            0          1d
default       canopy-2965694291-kjbqq                                             1/1       Running            0          1d
...
seu           hello-world-v13-1574404032-4hzxd                                    1/1       Running            0          62d
...
>>> describe pod 
                  ...
                  canopy-2965694291-f5f6c        Running 
                  canopy-2965694291-kjbqq        Running 

>>> describe pod canopy-2965694291-f5f6c
Error from server (NotFound): pods "canopy-2965694291-f5f6c" not found
Got error: exit status 1

>>> describe pod hello-world-v13-1574404032-4hzx
Name:       hello-world-v13-1574404032-4hzxd
Namespace:  seu
...
c-bata commented 6 years ago

Thanks for using kube-prompt.

kube-prompt just wraps kubectl like: https://github.com/c-bata/kube-prompt/blob/master/kube/executor.go#L20-L27

So It looks that your problem is no relevant to namespace. And your problem is also occurred when just executed following command directly. Can you try this?

$ kubectl describe pod canopy-2965694291-f5f6c
cgilling commented 6 years ago

I looked into the code a bit and it seems like the issue is that the completer always uses the default namespace when looking pods (see here)

Where as since the executor is shelling out to kubectl it will use the default namespace as setup by the current context that is being used.

carolynvs commented 6 years ago

Looks like this was fixed in 49b6437a0dfe633dd2cef51bf1d67b7b8637b75d.

jroberts235 commented 6 years ago

@cgilling - I agree that when working outside of the default context, some of the features provided by kube-prompt break. ex. ">>> -n myNamespace get po" Normally cube-prompt would allow me to tab complete the 'get' verb, and then suggest po, then provide a list of pods, but it doesn't recognize the -n.

I've gotten around this by simply setting the default namespace in my context using: kubectl config set-context $(kubectl config current-context) --namespace=<insert-namespace-name-here> OR in the kube-prompt paradigm, 'config set-context $(kubectl config current-context) --namespace='

Then I can work in my most used namespace and enjoy the creature comforts provided by this very handy tool ;)

It sounds like several people here, like me, need to work in multiple namespaces, and this workaround doesn't solve for rapid namespace changes, so I think better namespace support in kube-prompt would be a worth while improvement.

Keep up the good work @c-bata !

Cheers

c-bata commented 6 years ago

Hi there! As @carolynvs says, this problem has already fixed at master branch. But there are some important changes I want to like:

So please wait until few weeks later. I promised kube-prompt will be really better from the next release.

cgilling commented 6 years ago

great thanks