derailed / k9s

🐶 Kubernetes CLI To Manage Your Clusters In Style!
https://k9scli.io
Apache License 2.0
27.32k stars 1.71k forks source link

deleting namespace hotkeys #2104

Open gyorokpeter opened 1 year ago

gyorokpeter commented 1 year ago

Right now when switching to a new namespace, it automatically gets added to the numeric hotkeys. However the mapping from number to namespace is pretty arbitrary, and eventually the list gets full of junk when browsing random namespaces.

Therefore there should be a way to delete from this list, or if there already is, the help should do a better job at describing how to do it.

The workaround for now is to dig into the k9s config file and delete the entries from there (it's under favorites).

dongho-jung commented 1 year ago

indeed. it's convenient but somewhat arbitrary so that gives poor UX I think.

placintaalexandru commented 1 year ago

Hello @gyorokpeter When the delete happens you want to be prompted with a window and then you can choose which namespaces to delete? I am trying to understand if your requirement is different from this or providing something that always keeps some predefined namespaces on top would satisfy your need.

gyorokpeter commented 1 year ago

That other issue is about adding and reordering the namespaces from the command line, mine is to be able to delete them from the GUI. For example there could be a hotkey that opens a little window showing the namespaces and allow rearranging or deleting them. Or it could be done by changing the /ns view to display the hotkeys next to the namespaces and include reassign/delete facilities.

nyarly commented 1 year ago

I'm having a related irritation: I'm having to make changes to batches of Deployments in different namespaces. There's probably a better way to do this, but it's convenient to go :deploy, then /backend to scope down the right deployment. Then I can roll through the numbers to do whatever to each one.

If I have to :namespace and select one that isn't on the list, I have to also re-browse to :deploy /backend. So a) being able to boot namespaces off the list would be handy for maintaining the list nicely, or b) a namespace switch key that let me switch without losing my focus or c) a way to quickly reapply a particular focus would all smooth this rough edge.

placintaalexandru commented 1 year ago

I totally forgot about this. I'll try to insert it in my schedule. I apologize

placintaalexandru commented 1 year ago

I'm having a related irritation: I'm having to make changes to batches of Deployments in different namespaces. There's probably a better way to do this, but it's convenient to go :deploy, then /backend to scope down the right deployment. Then I can roll through the numbers to do whatever to each one.

If I have to :namespace and select one that isn't on the list, I have to also re-browse to :deploy /backend. So a) being able to boot namespaces off the list would be handy for maintaining the list nicely, or b) a namespace switch key that let me switch without losing my focus or c) a way to quickly reapply a particular focus would all smooth this rough edge.

@nyarly, from my understanding, isnt't your issues closer to this #2122: start k9s with a predefined list of namespaces and then you can switch from namespace to namespace with your selection without losing the focus

nyarly commented 1 year ago

Reading #2122, that flow sounds like I'd need to collect a set of namespaces and exit k9s, then re-run with the appropriate --namespaces flag. Maybe not the worst thing in the world, but when I need to manage >9 namespaces it's a little bit of a hassle.

Maybe the thing is that k9s is the wrong tool for this job, and I should be doing the Right Thing and scripting kubectl. For my use case (where namespaces are used to scope tenants), there are often little tasks that need to be done the same for ~12 namespaces, so k9s seems like the right thing to use... But that ~12 is only going to increase, so I should probably be thinking about an alternative anyway.

placintaalexandru commented 1 year ago

@nyarly, the thing is that, the way k9s works at the moment, you can't have more than 9 namespaces in that digit binding list (8 + all)

placintaalexandru commented 1 year ago

@gyorokpeter, does this fit your needs?

  1. You go to the ns view: :ns
  2. Press Shift + d and a dialog opens where you can choose which namespaces to delete (except all)
gyorokpeter commented 1 year ago

@placintaalexandru That looks like it would work. I assume you meant "except all" instead of "expect all".

vit-lebediev commented 1 year ago

I came here for the same feature, but gosh, I hope that ctrl-d in this case won't delete without a warning. Otherwise, I would expect a lot of accidentally deleted namespaces :D

placintaalexandru commented 1 year ago

No, it doesnt delete any ns from the actual cluster @vit-lebediev No kubernetes api stuff is called

vit-lebediev commented 1 year ago

@placintaalexandru yes the shift + d doesn't but ctrl+d does. They are pretty similar and muscle memory might easily lead to using ctrl+d instead of shift+d.

But, I'm still relatively new to k9s so I did not have a chance to delete namespaces with ctrl+d before. I've just tried and it asks for confirmation, so it should be just fine.

derailed commented 1 year ago

Thank you all for pipping in!

The idea behind favs ns feature is k9s records your ns context while navigating a cluster. The favs ns list is updated/evicted as you are perusing the cluster tracking your last used ns up to 9+allNS. Why only 10 you might ask? To make key bindings easier relying on single number keys 0-9.

As per this issue, the list is not readily manageable within the ui (as @nyarly correctly points out!) as it is automated and since k9s continually curates the list, manually editing the config is kind of pointless. Tho we could offer an ability to change that list in the ui, that would be overridden once the user issues :res nsXX or k9s -n commands and one would have to keep editing that list upon updates to maintain her favorites.

But this use case seems different aka I want to specify my top ~10 fav ns and don't want k9s to automatically manage it. So in this case, it sounds like one could make up her top <10 fav ns and that list would not change during a session unless otherwise edited. Thus favs ns recording behavior could be something the user should opted in/out via a new config flag??

Another feature that one could readily leverage for this use case are k9s aliases. Defining dpns1, dpns2, etc... will get you in the ballpark and the favs list will be auto updated without having to manually curate it. Which seems like a better option (imho) since in the future, we could offer viewing resources using a collection of ns aka :dp ns1,ns2

Is this correct or am I missing it?

nyarly commented 1 year ago

This is maybe a different feature, but my reason for wanting more control over namespace hotkeys is that it's the only way to change only the namespace of my view. Since I often find myself needing to run through actions over several namespaces or compare between two namespaces, my workflow often starts with a "pointless" switch to a couple of namespaces so that I can choose a different resource in the second one, search with that resource to narrow my focus, and then toggle between with hotkeys.

For me (and I don't know who else...) I'd even prefer a way to change parts of the view focus/context without having to start from scratch. In other words, being able to change the namespace I'm reviewing without leaving :deploy,/service-1 - right now, without hotkeys, I have to "stop" in :namespace, choose one, and then my focus resets to unfiltered :pods.

I don't know if this relates to any actual implementation abstraction, but my intuition of how k9s works is that any particular view consists of "co-ordinates" - (context, namespace, resource type, text filter), where the position on axes to the right may depend on where we are on the left - not every namespace exists in every context. Being able to change an axis independent of the others, and without affecting the others is really useful, and hotkeys are the only way I know to do that for namespaces.

derailed commented 11 months ago

@nyarly Thanks for your input! You could leverage cmd aliases to narrow 2 of the dimensions in this tuple. Would this help?

nyarly commented 11 months ago

It would depend on how easily aliases could be added, especially by e.g. a shell script