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

Combining context and namespace switching only works sporadically (e.g. ":pod foo-ns @ctx-dev") #2747

Closed
itd-fsc opened this issue Jun 17, 2024 · 0 comments · Fixed by #2750

Comments

@itd-fsc
Copy link

itd-fsc commented Jun 17, 2024




Describe the bug
When trying to switch the context and the namespace at the same time with commands like

pod foo-ns @ctx-dev
pod bar-ns @ctx-test

this only works very sporadically. Often only the context switch is performed and the last namespace of that context used instead.
But sometimes it works on the first try.
Also something strange seems to be happening in the background if it does fail, as switching contexts to another context and back results in the desired namespace being selected.
This seems to me like a race condition between updating the namespace and the loading of the namespace during the context switching.

To Reproduce
Steps to reproduce the behavior:

  1. pod @ctx-test
  2. Choose a namespace in ctx-dev that was not the active one before and run pod foo-ns @ctx-dev
  3. Sometime the namespace foo-ns of ctx-dev is now selected
  4. Otherwise run pod @ctx-test followed by pod @ctx-dev to reach the desired namespace foo-ns

Historical Documents
Debug logs when it works. Starting in context ctx-test, the running :pod foo-ns @ctx-dev:

�[90m2:16PM�[0m �[32mINF�[0m �[1m🐶 K9s starting up...�[0m
�[90m2:16PM�[0m DBG [Namespace] Invalid favorite found 'buzz' - false
# invalid favorite found appears a few times
�[90m2:16PM�[0m DBG Active Context "ctx-test"
�[90m2:16PM�[0m �[32mINF�[0m �[1m✅ Kubernetes connectivity�[0m
# invalid favorite found appears a few times
�[90m2:16PM�[0m DBG No custom skin found. Using stock skin
�[90m2:16PM�[0m DBG Factory START with ns `"bar-ns"
�[90m2:16PM�[0m DBG Fetching latest k9s rev...
�[90m2:16PM�[0m DBG K9s latest rev: "v0.32.5"
�[90m2:16PM�[0m DBG No custom skin found. Using stock skin
�[90m2:16PM�[0m DBG [Namespace] Invalid favorite found 'foobar' - false
�[90m2:16PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:16PM�[0m DBG Switching context "ctx-dev"
�[90m2:16PM�[0m DBG ClusterInfo updater canceled!
# invalid favorite found appears a few times
�[90m2:16PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:16PM�[0m DBG Factory START with ns `"foo-ns"
�[90m2:16PM�[0m DBG --> Switching Context "ctx-dev" -- "foo-ns" -- "pod"
�[90m2:16PM�[0m DBG No custom skin found. Using stock skin
�[90m2:16PM�[0m DBG [Namespace] Invalid favorite found 'bar-ns' - false

Debug logs when it only works on the second try context switch. So starting in ctx-test:

  • pod foo-ns @ctx-dev
  • pod @ctx-test
  • pod @ctx-dev
=> now in `foo-ns`

�[90m2:47PM�[0m �[32mINF�[0m �[1m🐶 K9s starting up...�[0m
�[90m2:47PM�[0m DBG Active Context "ctx-test"
�[90m2:47PM�[0m �[32mINF�[0m �[1m✅ Kubernetes connectivity�[0m
# invalid favorite found appears a few times
�[90m2:47PM�[0m DBG No custom skin found. Using stock skin
�[90m2:47PM�[0m DBG Factory START with ns `"bar-ns"
�[90m2:47PM�[0m DBG Fetching latest k9s rev...
�[90m2:47PM�[0m DBG K9s latest rev: "v0.32.5"
�[90m2:47PM�[0m DBG No custom skin found. Using stock skin
# invalid favorite found appears a few times
�[90m2:47PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:47PM�[0m DBG Switching context "ctx-dev"
�[90m2:47PM�[0m DBG ClusterInfo updater canceled!
# invalid favorite found appears a few times
�[90m2:47PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:47PM�[0m DBG Factory START with ns `"foo-ns"
�[90m2:47PM�[0m DBG --> Switching Context "ctx-dev" -- "foo-ns" -- "pod previous-ns"
�[90m2:47PM�[0m DBG No custom skin found. Using stock skin
# invalid favorite found appears a few times
�[90m2:47PM�[0m DBG Saved context config for: "ctx-test"
�[90m2:47PM�[0m DBG Switching context "ctx-test"
�[90m2:47PM�[0m DBG ClusterInfo updater canceled!
# invalid favorite found appears a few times
�[90m2:47PM�[0m DBG Saved context config for: "ctx-test"
�[90m2:47PM�[0m DBG Factory START with ns `"bar-ns"
�[90m2:47PM�[0m DBG --> Switching Context "ctx-test" -- "bar-ns" -- "pod"
�[90m2:47PM�[0m DBG No custom skin found. Using stock skin
# invalid favorite found appears a few times
�[90m2:48PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:48PM�[0m DBG Switching context "ctx-dev"
�[90m2:48PM�[0m DBG ClusterInfo updater canceled!
# invalid favorite found appears a few times
�[90m2:48PM�[0m DBG Saved context config for: "ctx-dev"
�[90m2:48PM�[0m DBG Factory START with ns `"k8s-current-ns"
�[90m2:48PM�[0m DBG --> Switching Context "ctx-dev" -- "k8s-current-ns" -- "pod foo-ns"
�[90m2:48PM�[0m DBG No custom skin found. Using stock skin
# invalid favorite found appears a few times

Expected behavior
The namespace selected in the command is active after the context switch .

Versions:

  • OS: Ubuntu 22.04
  • K9s: v0.32.5
  • K8s: v1.29.4-eks-036c24b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant