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

Introduce Resource creation and duplication functionality #954

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

NickyMateev
Copy link

@NickyMateev NickyMateev commented Nov 21, 2020

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:
#191 and #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

@derailed
Copy link
Owner

@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.

@merusso
Copy link

merusso commented Oct 28, 2022

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.

@eviscares
Copy link

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?

@b1zzu
Copy link

b1zzu commented Jun 7, 2023

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

@Slach
Copy link

Slach commented Jun 8, 2023

@NickyMateev could you merge latest master and resolve conflicts?

@Ghilteras
Copy link

@NickyMateev @derailed can we push this PR through?

@RafalSkolasinski
Copy link

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?

@fawaf
Copy link

fawaf commented Feb 23, 2024

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.

nobbs pushed a commit to nobbs/k9s that referenced this pull request Feb 23, 2024
This commit refactors the code from PR derailed#954 to make it work with current
master, as well as only enable the "Create" and "Duplicate" actions when
K9s is not in read-only mode.

Also, both actions will use `kubectl create` instead of `kubectl apply` to
create the resource, as this will automatically prevent the user from overwriting
an existing resource by name.
@nobbs
Copy link
Contributor

nobbs commented Feb 23, 2024

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 added a commit to nobbs/k9s that referenced this pull request Feb 23, 2024
This commit refactors the code from PR derailed#954 to make it work with current
master, as well as only enable the "Create" and "Duplicate" actions when
K9s is not in read-only mode.

Also, both actions will use `kubectl create` instead of `kubectl apply` to
create the resource, as this will automatically prevent the user from overwriting
an existing resource by name.
nobbs added a commit to nobbs/k9s that referenced this pull request Mar 2, 2024
This commit refactors the code from PR derailed#954 to make it work with current
master, as well as only enable the "Create" and "Duplicate" actions when
K9s is not in read-only mode.

Also, both actions will use `kubectl create` instead of `kubectl apply` to
create the resource, as this will automatically prevent the user from overwriting
an existing resource by name.
nobbs added a commit to nobbs/k9s that referenced this pull request Mar 4, 2024
This commit refactors the code from PR derailed#954 to make it work with current
master, as well as only enable the "Create" and "Duplicate" actions when
K9s is not in read-only mode.

Also, both actions will use `kubectl create` instead of `kubectl apply` to
create the resource, as this will automatically prevent the user from overwriting
an existing resource by name.
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.

None yet

10 participants