k9s icon indicating copy to clipboard operation
k9s copied to clipboard

Introduce Resource creation and duplication functionality

Open NickyMateev opened this issue 4 years ago • 9 comments

Introduce Resource creation and duplication functionality

I love k9s but one thing which always bugged me was having to create new resources - it usually meant that I had to:

  1. Open a new terminal window and ditch k9s
  2. Create a new temporary YAML file somewhere to paste the resource yaml content
  3. kubectl apply -f temp.yaml
  4. Remove temp.yaml as it's no longer needed (or actually forget to delete it, which happens often which leads to junk/unused files on my file system)
  5. Go back to k9s

This is way too much of a hassle and at best it slows down an operator's workflow and at worst it may break his focus while working intensely on some issue as the operator now has to do all this miscellaneous stuff when all he wanted to do was to apply a new Kubernetes resource.

Proposal

This PR propose the addition of two new keybindings:

  • Add New keybinding (n key) to allow new resource creation while viewing pods, deployments, services etc... This opens a blank text editor where you can paste the yaml content of a Kubernetes resource (or multiple resources separated by ---) and upon closing the text editor the content will be applied to your Kubernetes cluster.
  • Add Duplicate keybinding (d key) in the YAML view to allow creation of new Kubernetes resources by using the current resource as a starting point. This again opens your text editor but this time it pre-populates it with the yaml content of the resource you were just viewing. This allows you to create similar resources by simply using the current one as your base and changing it as you wish. For example - you may be looking at a Kubernetes service of which you may want to create a copy of but maybe change up the ports, you would simply open up the YAML view for the specific service and press the Duplicate keybinding (d key), an editor would open and you would only need to change up the resource name (so it's unique) and the ports you as you like them to change.

The above two actions are things I often need to do and I'm sure other operators also have faced similar issues of having to switch contexts between k9s and another terminal window just to do them.

Related issues

There seem to be an previous (closed) issues which inquire about functionality about easily creating new resources: https://github.com/derailed/k9s/issues/191 and https://github.com/derailed/k9s/issues/496

Closing thoughts

To me k9s is an awesome tool which saves a ton of time when operating Kubernetes clusters. The only missing peace for me was creation of new resources with ease and quickness. I believe this PR proposed a solution to this missing peace which would make k9s a complete package for anyone who wishes to operate Kubernetes clusters with maximum efficiency.

newBtn duplicateBtn editMode

NickyMateev avatar Nov 21 '20 02:11 NickyMateev

@NickyMateev This is by far the best PR I've gotten to date. Well done Sir! As a rule I am not big on one of operations on a cluster. The source of truth resides on disk. Thus creating resources on the fly with no real backing makes me a little ill at ease. I think it might be a good thing to have a configurable user directory to save the results of new/dup so the operator can lasso those and put then under source control. Also we should put a guard around these actions are they should be considered dangerous and should not be exposed when the ready-only option is active.

derailed avatar Mar 22 '21 05:03 derailed

This seems like a great improvement to me.

I agree that long-lived objects should live in source control, but I often find that I need to create short-term objects for adhoc testing purposes. I often have to follow this process to copy such objects:

  1. Use kubectl get -o yaml to export the object to disk
  2. Modify the file as required
  3. Use kubectl apply to apply the object in the modified file.

This PR would greatly simplify this common workflow.

merusso avatar Oct 28 '22 19:10 merusso

Hey,

I just stumbled upn this by accident, and it would be the last thing that I need in my workflow to leave kubectl behind. I also just use cli object creation for short lived stuff, but for that it would be immenseley helpful.

Are there any blockers, or is there some way that one could help to move this along to get the functionality integrated?

eviscares avatar Feb 16 '23 08:02 eviscares

Hi, I really hope this PR will not be forgotten and will go trough

b1zzu avatar Jun 07 '23 20:06 b1zzu

@NickyMateev could you merge latest master and resolve conflicts?

Slach avatar Jun 08 '23 13:06 Slach

@NickyMateev @derailed can we push this PR through?

Ghilteras avatar Jun 28 '23 17:06 Ghilteras

Would love to see this feature in - is there anything else to do than just resolving conflicts? I see discussion about not exposing functionality in read-only mode?

RafalSkolasinski avatar Feb 23 '24 00:02 RafalSkolasinski

definite +1 as well. creating of new resources is even more important than duplication imo. both are great to have, but creation i think would be most used.

fawaf avatar Feb 23 '24 20:02 fawaf

Since this PR is already 3 years old and probably long forgotten by the original author, I've reworked this in a new one #2563. Maybe that one fits the bill and will see the light of day :)

nobbs avatar Feb 23 '24 21:02 nobbs