k9s icon indicating copy to clipboard operation
k9s copied to clipboard

Add support for delete context (Ctrl+D) from k9s

Open tadayosi opened this issue 3 years ago • 8 comments

Like other k8s resources, please add support for deleting a context with Ctrl+D in the contexts view. This would make it easier for me to clean up cluttered context settings with k9s.

What we'd normally do with kubectl is:

$ kubectl config get-contexts

and then:

$ kubectl config delete-context <chosen-context>

Please just support the same operation from k9s UI.

tadayosi avatar Feb 16 '21 05:02 tadayosi

I don't like the idea of using an standard linxu key-combo for such an critical task.

rockaut avatar Feb 23 '21 10:02 rockaut

@rockaut Is this so critical? It's just deleting an authentication cache to a k8s cluster from client side. It shouldn't do anything to the remote cluster.

tadayosi avatar Feb 24 '21 06:02 tadayosi

Sorry I got this somewhat wrong ... but ctrl+d is not only deleting in contexts but in any view. So you can also delete a pod with ctrl+d thought there is a confirmation box. image

But you're right my comment was irrelevant for your issue sorry.

rockaut avatar Feb 25 '21 14:02 rockaut

👍 for this feature request.

azarudeena avatar Mar 09 '21 17:03 azarudeena

This plugin works when added to your ~/.k9s/plugin.yml; however, k9s doesn't allow reload/refresh of the contexts (you need to quit/restart):

plugin:
  deleteContext:
    shortCut: Ctrl-D
    confirm: true
    description: Delete kubectl context
    scopes:
    - contexts
    command: kubectl
    background: true
    args:
    - config
    - delete-context
    - $NAME

Adding the ability to refresh contexts would be a great MVP feature for this. I've been wanting to add a plugin for pulling kubeconfigs from ClusterAPI & gcloud also, which would benefit from reload-able contexts as well.

spiegela avatar Jul 08 '21 18:07 spiegela

Great plugin, thank you. It works on usual k8s but it fails on AWS, they are naming its clusters with arn and it need full name to be deleted: arn:aws:eks:eu-west-2:1234567890:cluster/delteme kubectl config delte-context delteme #failed kubectl config delte-context arn:aws:eks:eu-west-2:1234567890:cluster/delteme #cluster deleted

I have tried things like

- "$NAME"
- \"$NAME\"

... but without any results. Do you have any hint? Thanks

robinpecha avatar Feb 16 '23 09:02 robinpecha

@robinpecha I'm using - $COL-NAME and it works fine.

From docs: $COL-<RESOURCE_COLUMN_NAME> use a given column name for a viewed resource. Must be prefixed by COL-!

KrzysztofJopek avatar Jul 17 '23 08:07 KrzysztofJopek

this worked for me:

arothste@console:~$ cat ~/.config/k9s/plugins.yaml
---
plugins:
  deleteContext:
    shortCut: Ctrl-D
    confirm: true
    description: Delete kubectl context
    scopes:
      - contexts
    command: kubectl
    background: true
    args:
      - config
      - delete-context
      - $COL-NAME

andrewrothstein avatar Apr 17 '24 16:04 andrewrothstein