Skip to content
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

Context Switch unreliable/not working #2446

Closed
mj-jackson opened this issue Jan 9, 2024 · 13 comments
Closed

Context Switch unreliable/not working #2446

mj-jackson opened this issue Jan 9, 2024 · 13 comments
Labels
bug Something isn't working question Further information is requested

Comments

@mj-jackson
Copy link

mj-jackson commented Jan 9, 2024




Describe the bug
After upgrading to 0.30.x / 0.31.x switching contexts via :ctx is very unreliable. Sometimes it works, but most often it will get stuck. Autorefresh is no longer working and the only option available is to quit, set context manually via kubectl and start k9s again.

I am working on macOS, cannot test if other OSs are affected as well.

To Reproduce
Steps to reproduce the behavior:

  1. Install k9s
  2. configure multiple contexts
  3. Set a specific context
  4. use :ctx to show configured contexts
  5. choose a different one
  6. use :pods to show pods
  7. pod-view will not autorefresh anymore (and most of the time will show the old context)

Expected behavior
In versions 0.2x.x while selecting a different context put you back to the last view used, meaning: Navigating from :pods to :ctx, selecting a context would select the context and automatically set you back to :pods. This is the expected behavior.

Versions (please complete the following information):

  • OS: macOS 14.2
  • K9s: 0.30.x & 0.31.x
  • K8s: 1.25.16

Additional context
When selecting the new context, the marker (*) does not update in the info area at the top. Other information, eg. Context, Cluster, is updated, but "CPU" and "MEM" freezes at current value or falls to 0% and does not update anymore.
I install via homebrew, deleting the config folder /Users/my_user/Library/Application Support/k9s completely and reinstalling did not work.

@jhuspek
Copy link

jhuspek commented Jan 9, 2024

Same for me, but I use windows & PowerShell 7.4.0:

OS: Windows 11 Enterprise 22H2 (22621.2861)
K9s: 0.30.x & 0.31.x
K8s: v1.26.3

@derailed derailed added bug Something isn't working question Further information is requested labels Jan 9, 2024
@derailed
Copy link
Owner

derailed commented Jan 9, 2024

@jhuspek Tx for the report! I could not repro this at the ranch using v0.31.1. I did however find an issue if you select the current context while in ctx view. It should nav to the pod view but doesn't.
When you say the pod view does not seem to refresh are you using a different context in the same cluster or a context in a different cluster? Tried both scenarios but could not repo??

derailed added a commit that referenced this issue Jan 9, 2024
@ginomempin
Copy link

ginomempin commented Jan 11, 2024

I can still repro this with the v0.31.4 release.

Env Details:

  • OS: macOS 12.5.1
  • K9s Rev: v0.31.4
  • K8s Rev: v1.20.12

@derailed
In response to your question

When you say the pod view does not seem to refresh are you using a different context in the same cluster or a context in a different cluster?

1st,
As you mentioned, selecting a context does not auto-switch to the pod view (or any view). It stays stuck at the Contexts view, but I do see the context changing in the Context: info at the top of the UI. Even when I switch to the Deployments or Pod view, the list is still stale/outdated, and it still shows resources from the previous context. I need to restart k9s (CTRL-C then re-run k9s) to get the updated list.

2nd,
Even on restarting k9s, it still shows the Contexts view, with the new context selected.

3rd,
Same issue for both:

  • Switching to different context in same cluster
  • Switching to different context in different cluster

If there's some more info I can give (like logs, etc.), let me know.

@derailed
Copy link
Owner

@ginomempin Thank you for the details! Of course none of these repro in my env as it works as expected ;(
I suspect you are running into a context config validation issue. Could you share both your debug logs and your context specific config.yaml. Best guess the file is corrupt with a trailing alhost or something like that and failing validation??

@derailed derailed reopened this Jan 11, 2024
@flamadrid-jsmdg
Copy link

I've got the error, when there is no context set.

10:00AM ERR config refine failed error="unable to activate context \"\": getcontext - invalid context specified: \"\""
10:00AM ERR Fail to load global/context configuration error="unable to activate context \"\": getcontext - invalid context specified: \"\""

@ginomempin
Copy link

ginomempin commented Jan 11, 2024

@derailed

Thanks for re-opening.

your debug logs

I found something in the k9s.log (should have checked earlier).
Whenever I'm switching to a context on v0.31.4, I get:

6:20PM ERR getcontext - invalid context specified: "Mempin-my-namespace"

The full context name is supposed to be "my-cluster-Gino Mempin-my-namespace".
My context name has a space in it :|
Might that be it?
(I'm using k9s on an internal/company-managed K8s, and for reasons, the K8s contexts includes "FirstName LastName".)

Just to be sure, I re-installed v0.29.1, and sure enough I don't get any of those ERR logs on that version.

your context specific config.yaml

I'm not using any context-specific config.yaml.
I'm using whatever default comes with the installation.

@mj-jackson
Copy link
Author

My context name has a space in it :|
Might that be it?

I think that's it.

The behavior did not change for me as well, even with 0.31.4. But I remembered that my context names do have whitespaces in them, too. So I changed them and now it seems to work.

I did not think of it since it was working as expected with the 0.2x versions.

@derailed
Copy link
Owner

@flamadrid-jsmdg I think v0.31.4 fixed this issue?

@ginomempin Thanks for the details! Which platform are you using? did not occur to me that contexts can have spaces?? Anyhow still works for me here at the ranch on macOS?? You should still be able to change your kubeconfig and edit the spaces (as @mj-jackson mentioned) and see if you are happier?? If so we have a bug ;(

@flamadrid-jsmdg
Copy link

@derailed Unfortunately not, if there a context set, yes, k9s starts up fine. But if no context is set, like when running kubectl config unset current-context then I see "panic: no client connection detected"
And then the logs show:

9:52AM ERR config refine failed error="unable to activate context \"\": getcontext - invalid context specified: \"\""
9:52AM ERR Fail to load global/context configuration error="unable to activate context \"\": getcontext - invalid context specified: \"\""

@ginomempin
Copy link

ginomempin commented Jan 12, 2024

@derailed

Which platform are you using?

It's an in-house K8s cluster, not any of the public platforms.
The infra team provides a tool for authenticating to the cluster, and accessing it from our local env.
But it does create contexts with spaces.

You should still be able to change your kubeconfig and edit the spaces

Yeah, it seems I can do that.
I haven't fully tested it out, it does break quite a bit of scripts/tooling on my end 😅
Can it at least be noted as a warning in the k9s docs?

@ginomempin
Copy link

ginomempin commented Jan 16, 2024

@derailed

You should still be able to change your kubeconfig and edit the spaces (as @mj-jackson mentioned) and see if you are happier??

I edited my .kube/config to replace context names to remove spaces (have to this manually on my env, but that's my problem). So now, switching contexts on the latest 0.31.5 version is now working, and so yes, I am now happier.

Thanks for responding and checking.

@derailed
Copy link
Owner

Fixed v0.31.5

thejoeejoee pushed a commit to thejoeejoee/k9s that referenced this issue Feb 23, 2024
* [Bug] Fix derailed#2428

* fix derailed#2446

* fix derailed#2449

* schemas updates

* Add debug info

* v0.31.2 rel notes
placintaalexandru pushed a commit to placintaalexandru/k9s that referenced this issue Apr 3, 2024
* [Bug] Fix derailed#2428

* fix derailed#2446

* fix derailed#2449

* schemas updates

* Add debug info

* v0.31.2 rel notes
@feanor777
Copy link

The same issue for me on 0.32.4 -> not able to swtich ctx.
@ginomempin answer helped, removed spaces from the context name in my kubeconfig file (~/.kube/config) and now working fine.

P.S. just open the file ~/.kube/config go to contexts: section and removed the namespace in the name: field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants