romkatv / powerlevel10k

A Zsh theme
MIT License
44.9k stars 2.13k forks source link

kubecontext not showing when kubectl is in the buffer. #1242

Closed wadkar closed 3 years ago

wadkar commented 3 years ago

Hey, thanks a lot for p10k.

I am trying to debug why kubecontext is not showing up when kubectl is in the command buffer. I have gone through #318 and have some basic idea of how it works. I looked at the p10k help display and then:

❯ p10k display -a '*/kubecontext'
❯ printf '%-32s = %q\n' ${(@kv)reply}
1/right/kubecontext              = hide

So it's hidden (by default). It used to show up earlier as soon as I typed kubectl but it doesn't show up anymore.

Of course, I did a p10k configure to reconfigure p10k (with my favorite wizard options).

I also see that ❯ echo $POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND returns kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile. I am on powerlevel10k-v1.14.6@d26bdcd6 using prezto's prompt module.

Can you please suggest ways to debug, or tell me how to disable the autohide for kubecontext?

Let me know if you want the ~/.p10k.zsh. I have instant-prompt enabled FWIW.

romkatv commented 3 years ago

Can you please suggest ways to debug, or tell me how to disable the autohide for kubecontext?

You can disable auto-hide by removing POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND from your config. See https://github.com/romkatv/powerlevel10k#why-some-prompt-segments-appear-and-disappear-as-im-typing.

If this will actually help, it means some other plugin you are using is interfering with powerlevel10k. Try disabling plugins one by one to find the culprit.

If removing POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND doesn't help, please post the output of the following command:

whence kubectl && kubectl config view -o=yaml
romkatv commented 3 years ago

Closing due to inactivity.

wadkar commented 3 years ago

My apologies for not responding earlier. While I was unable to deduce which plugin is causing the problem, I can confirm that unsetting the POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND variable sometimes work. I use kubectx and kubens to switch context and namespace. Another potential source of problem could be that the K8s ApiServer is an AWS EKS Server, and I need saml2aws to access it. The SAML auth tokens expire every few hours and kubectl commands fail without the auth token.

I can see the context again after successfully auth'ing with saml2aws and selecting context+namespace using kubectx && kubens. Interestingly enough, only a different context gets shown in the prompt and not the one on which I was working.

romkatv commented 3 years ago

If you figure out a way to reproduce this reliably (in a way that I can do on my machine), please open a new issue.

wadkar commented 3 years ago

Sure, I suspect it's got to do with saml2aws and how the user section of my ~/.kube/config has:

- name: arn:aws:eks:us-east-1:1234567890:cluster/k8s-test
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-1
      - eks
      - get-token
      - --cluster-name
      - k8s-test
      command: aws
      env: null

Would you happen to have any working AWS+EKS clusters with saml2aws for auth?

I think it'll be rather difficult to reproduce without such a specific use case.

romkatv commented 3 years ago

Powerlevel10k gets all info from the output of kubectl config view -o=yaml. Does this call fail when you are not authenticated? All it's supposed to do is print your local config. If on your system it doesn't work, can you figure out how to force kubectl to print its config without network I/O of any kind?

wadkar commented 3 years ago

Ah, then maybe it's the asdf which is causing the problem! I have just set asdf global kubectl 1.17.17 so kubectl will work from any dir. That should ensure kubectl config view -o=yaml will always return something sensible instead of:

❯ kubectl
No version set for command kubectl
Consider adding one of the following versions in your config file at
kubectl 1.19.3
kubectl 1.16.13
kubectl 1.13.0
kubectl 1.17.13
kubectl 1.17.17

Now any new shell shows the context in the prompt as soon as I type kubectl (or even kb which is aliased to kubectl in my setup).

I think it should be safe to close this issue. I will reopen another if the problem persist.

Edit: No, the kubectl config view -o yaml does not fail while not authenticated with saml2aws to AWS/EKS.

Thanks again for your help and amazing p10k work!

romkatv commented 3 years ago

Thanks for updating the issue. I'm glad this is resolved.

Edit: No, the kubectl config view -o yaml does not fail while not authenticated with saml2aws to AWS/EKS.

Good to know. This is the expected behavior.