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

Use current k9s NS if new context has no default NS #2197

Merged
merged 2 commits into from
Nov 12, 2023

Conversation

mikutas
Copy link
Contributor

@mikutas mikutas commented Aug 14, 2023

closes #1461

Switching context causes resetting active namespace for now and as a result default NS is always activated.

@mikutas mikutas marked this pull request as ready for review August 14, 2023 14:37
@mikutas mikutas changed the title prevent resetting active ns when switching ctx Fix resetting active namespace when switching ctx Aug 26, 2023
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikutas Thank you for your PR. I think this issue was brought up before and we'd settled on using the namespace associated with the new context.

@@ -403,10 +403,7 @@ func (a *App) switchContext(name string) error {
a.Halt()
defer a.Resume()
{
ns, err := a.Conn().Config().CurrentNamespaceName()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current behavior is correct i.e when switching context we want to use the default namespace associated with that context vs using the namespace in the k9s config. For example if ctx1 specifies default namespace ns1 but the k9s config (if it exists!) specifies ns2 then k9s should use ns1 as the default namespace. This proposal would always override the namespace with the k9s config namespace or default if not set.
That said, a case could be made if the new context does not specify a namespace where we could override with the last visited namespace from the k9s config if set....

Does this make sense?

Copy link
Contributor Author

@mikutas mikutas Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I think I got the intent of existing behavior. 💡
I missed the usecase that we specify ns expressly in kubeconfig.
On the other hand, I'm not in the habit of specifying ns in kubeconfig, so the fallback suggested will be very convenient for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, long time no see @derailed .
Is there something I can do to go ahead?

@mikutas mikutas requested a review from derailed August 29, 2023 13:42
@mikutas mikutas changed the title Fix resetting active namespace when switching ctx Use current k9s NS if new context has no default NS Nov 9, 2023
@mikutas mikutas force-pushed the 1461 branch 3 times, most recently from b684a0b to 74bb63a Compare November 9, 2023 10:07
and set k9s's active ns if no ns specified in the context
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikutas Thanks for this update!

@derailed derailed merged commit 23e600b into derailed:master Nov 12, 2023
1 check passed
rm-hull added a commit to rm-hull/k9s that referenced this pull request Nov 12, 2023
* 'master' of github.com:derailed/k9s: (130 commits)
  added flux suspended resources retrieval plugin (derailed#1584)
  Provide white blur so images work in dark modes (derailed#1597)
  Add context to get-all (derailed#1701)
  fix brew command in the readme (derailed#2012)
  Add support for using custom kubeconfig with log_full plugin (derailed#2014)
  feat: allow for multiple plugin files in $XDG_DATA_DIRS/k9s/plugins (derailed#2029)
  Clean up issues introduced by derailed#2125 (derailed#2289)
  Pod view resembles more the output of kubectl get pods -o wide (derailed#2125)
  Update README.md with snap install (derailed#2262)
  Add snapcraft config (derailed#2123)
  storageclasses view keeps the same output as kubectl get sc (derailed#2132)
  Fix merge issues with PR derailed#2168 (derailed#2288)
  Add colour config for container picker (derailed#2140)
  Add env var to disable node pod counts (derailed#2168)
  Use current k9s NS if new context has no default NS (derailed#2197)
  Bump actions/setup-go from 4.0.1 to 4.1.0 (derailed#2200)
  fix: trigger a single log refresh after changing 'since' (derailed#2202)
  Add crossplane plugin (derailed#2204)
  fix(derailed#1359): add option to keep missing clusters in config (derailed#2213)
  K9s release v0.28.2
  ...
thejoeejoee pushed a commit to thejoeejoee/k9s that referenced this pull request Feb 23, 2024
* Fix resetting active namespace when switching ctx

* Respect existing behavior

and set k9s's active ns if no ns specified in the context
placintaalexandru pushed a commit to placintaalexandru/k9s that referenced this pull request Apr 3, 2024
* Fix resetting active namespace when switching ctx

* Respect existing behavior

and set k9s's active ns if no ns specified in the context
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 this pull request may close these issues.

change context(config namespace active reset)
2 participants