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

Generate aliases #20

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

Generate aliases #20

wants to merge 80 commits into from

Conversation

Dbz
Copy link
Owner

@Dbz Dbz commented Aug 20, 2021

Generate aliases!

@patmessina
Copy link
Collaborator

What do you think about removing bin/generate-kube-aliases from git? Seems like something to add to the .gitignore. I didn't want to do that without asking you first

Yea, I think so. Im thinking we generate a default file for users to source and only if they want they can use the generate tool. Figure we can make them into releases. Probably should have it ignore bin completely.

@patmessina
Copy link
Collaborator

This last commit allows for additional aliases. Essentially we can generate everything to a single file.

Im happy to revert back if this isnt the direction youd like to go.

@patmessina
Copy link
Collaborator

Guess let me know what you think from here.

Couple of thoughts. I have.

  • Probably can change cmds to a list like I had additional. I dont think it needs to be a map.
  • More tests - make sure things fail nicely
  • Build a release
  • Redo readme - most users will probably just want to source the generated file

1. Remove leaky abstraction aliasNames
2. Refactor GenerateAdditional to Generate
3. Remove and update tests
@Dbz
Copy link
Owner Author

Dbz commented Aug 25, 2021

OK, here is the PR to remove the leaky abstraction. I did a little bit of extra refactoring to combine Generate and GenerateAdditional: #26

@Dbz
Copy link
Owner Author

Dbz commented Aug 25, 2021

Well, I think this is looking great.

I like all of your bullets. I would add we should make the user provided aliases go into a separate file so we're not overriding it on update.

Refactor Generate 

*  Remove leaky abstraction aliasNames
*  Refactor GenerateAdditional to Generate
*  Remove and update tests
@patmessina
Copy link
Collaborator

patmessina commented Aug 25, 2021

Hmmm... that seems to have broken stuff. Tests are passing, but if you actually use the tool its broken. I have fixed that (need to initialize the map) but now the tests are always passing. So gotta figure out what that is all about.

It seems to be true on commit before yours so I shall see.

@patmessina
Copy link
Collaborator

It is the TestMain function. Itll be fixed next commit.

Co-authored-by: Patrick Messina <patrick_messina@eogresources.com>
@Dbz
Copy link
Owner Author

Dbz commented Aug 26, 2021

So I realize, in order to allow folks to generate their own stuff, we do need to include a binary in git :( . I usually dislike that, so maybe let's generate one per release?

@patmessina
Copy link
Collaborator

Possible solution:

Don't provide it in the repository. And pretty much have one file that they can source. It'll have good defaults.

Have a binary that we keep with the release. That's where it belongs anyway. If users want to generate them they can download that release.

I imagine most people just wanna source a file and be done. But just in case, think we should have all the commands be copy and paste.

patmessina and others added 3 commits August 27, 2021 17:38
…d removed the extra bit in code (#28)

Co-authored-by: Patrick Messina <patrick_messina@eogresources.com>
* changed generate_aliases directory to generate

* changing readme

* minor readme changes

* Update README.md

comprehensive

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

aliases

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

Specifically

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

deleting here

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

d is for describe

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

this is more clear

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

examples == good

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* moved Generate Aliases information to customizing aliases

* added table of contents

* formatting

* added coming soon

* have examples

* Update README.md

How are so many of these wrong?

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* added additional example for prefix

* Update README.md

fine by me

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* example cutom alias

* added more content to generating aliases

* fixed table of contents

* customizing aliases yaml

* corrected table of contents

* added another example

* inital readme

* added make test

* Update README.md

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

* Update README.md

an

Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>

Co-authored-by: Patrick Messina <patrick_messina@eogresources.com>
Co-authored-by: Danny Burt <Dbz@users.noreply.github.com>
* Ignore bin

* Add comments to generated aliases

* Regenerate Aliases

* updated drain command. The old version was deprecated from kube

* added grep command to getting resources

* More example usages

* added watch all

* Add comment to additional section of readme

Minor changes

* Fix grep

* Fixe rules section

* Few more readme rules fixes

Co-authored-by: Patrick Messina <patrick_messina@eogresources.com>
@anupamsr
Copy link

anupamsr commented Nov 24, 2021

I made some modifications for my personal use to create aliases for powershell. I don't know go, so I am vary of opening a PR, but the basic idea is as follows

diff --git a/generate/pkg/generate/generate.go b/generate/pkg/generate/generate.go
index 069a456..e083c42 100644
--- a/generate/pkg/generate/generate.go
+++ b/generate/pkg/generate/generate.go
@@ -104,7 +104,9 @@ func GenerateAlias(w io.Writer, aliases *types.AliasCMDs) error {
                        lastResource = alias.Resource
                }

-               fmt.Fprintf(w, "alias %v=\"%v\"\n", aliasName, aliasCommand)
+               ps1prefix := "ps1_"
+               fmt.Fprintf(w, "function %v%v {%v $args}\n", ps1prefix, aliasName, aliasCommand)
+               fmt.Fprintf(w, "New-Alias -Name %v -Value %v%v\n", aliasName, ps1prefix, aliasName)
        }

        var comment string
@@ -121,7 +123,9 @@ func GenerateAlias(w io.Writer, aliases *types.AliasCMDs) error {
                        comment = alias.Comment
                }

-               fmt.Fprintf(w, "alias %v=\"%v\"\n", alias.Short, alias.CMD)
+               ps1prefix := "ps1_"
+               fmt.Fprintf(w, "function %v%v {%v $args}\n", ps1prefix, alias.Short, alias.CMD)
+               fmt.Fprintf(w, "New-Alias -Name %v -Value %v%v\n", alias.Short, ps1prefix, alias.Short)
        }
        return nil
 }

It would be very nice if something like this could be accommodated. I will work on fixing it...

@Dbz
Copy link
Owner Author

Dbz commented Nov 25, 2021

Hi @anupamsr . I'm happy to accommodate :)

What should do is work together on a PR to create a new generated file specifically for powershell users. Should should be able to do that with a minimal amount of code.

@patmessina
Copy link
Collaborator

@anupamsr -- started the support. Thank ya. 6199509

@anupamsr
Copy link

Hi. Is there a plan to add aliases for kubectl context? I mean, something like

--- a/aliases.yaml
+++ b/aliases.yaml
@@ -164,4 +164,13 @@ additional:
   - short: keit
     cmd: "kubectl exec -it"
     comment: "Exec alias."
+  - short: kk
+    cmd: "kubectl config"
+    comment: "Modify kubeconfig files."
+  - short: kkc
+    cmd: "kubectl config get-contexts"
+    comment: "Describe one or many contexts."
+  - short: kku
+    cmd: "kubectl config use-context"
+    comment: "Set the current-context in a kubeconfig file."

I am just about learning kubernetes devops so it if you think there is a better way, I would really appriciate knowing that.

@patmessina
Copy link
Collaborator

Sure, if you want you can open a pull request and Ill merge it in. If not, Ill add it.

@Dbz
Copy link
Owner Author

Dbz commented Jan 30, 2022

Yes, if you're going to open a PR which would be awesome, please base it off of this branch!

@anupamsr
Copy link

anupamsr commented Feb 3, 2022

Done. Please have a look: #34

Added aliases for kubectl config
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.

4 participants