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

Use go-git functionalities for common git operations #108

Merged
merged 1 commit into from
Jun 30, 2021

Conversation

a-hilaly
Copy link
Member

Part of aws-controllers-k8s/community#835

This patch updates all the helper functions to use go-git library
instead of having to call os/exec.Command/os/exec.CombinedOutput in
order to clone repository, fetch tags... These changes brings more
dependencies to our go.mod but in exchange it simplifies the way we
interact with git repositories and improves errors handling and
readability.

Future changes will also benefit from this patch, especially
conversation webhook generator that will need to checkout multiple
version tags.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@a-hilaly
Copy link
Member Author

Needs ATTRIBUTIONS.md update
/hold

@ack-bot ack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 25, 2021
@a-hilaly a-hilaly force-pushed the go-git branch 2 times, most recently from ecc9b22 to 6371c7b Compare June 25, 2021 16:44
cmd/ack-generate/command/common.go Outdated Show resolved Hide resolved
cmd/ack-generate/command/common.go Outdated Show resolved Hide resolved
cmd/ack-generate/command/common.go Show resolved Hide resolved
pkg/util/git.go Outdated Show resolved Hide resolved
)

// LoadRepository loads a repository from the local file system.
// TODO(a-hilaly): load repository into a memory filesystem (needs go1.16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How large would this be in memory? I know the aws-sdk-go has a large commit history and many, many tags.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

du -sh ~/.cache/aws-controllers-k8s/src/aws-sdk-go 
352M	/Users/hilalymh/.cache/aws-controllers-k8s/src/aws-sdk-go

I guess it's gonna be ~350M - I will do some profile on ack-generate binary before implementing it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RedbackThomson Is it a bad a idea to load such a big repository in memory?

command using `os/exec`

This patch updates all the helper functions to use `go-git` library
instead of having to call `os/exec.Command`/`os/exec.CombinedOutput` in
order to clone repository, fetch tags... These changes brings more
dependencies to our `go.mod` but in exchange it simplifies the way we
interact with git repositories and improves errors handling and
readability.

Future changes will also benefit from this patch, especially
conversation webhook generator that will need to checkout multiple
version tags.
@a-hilaly
Copy link
Member Author

/unhold

@ack-bot ack-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 29, 2021
@a-hilaly a-hilaly requested a review from vijtrip2 June 29, 2021 14:58
@vijtrip2
Copy link
Contributor

/approve

I am sure you tested this locally for some controller. Good to add the output in PR since there are no new unit tests.

@a-hilaly
Copy link
Member Author

Adding unit tests
/hold

@ack-bot ack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2021
@a-hilaly
Copy link
Member Author

Looks like it's very complex to unit test these util functions, and it's almost equivalent of testing the go-git library. @vijtrip2 and I agreed on leaving the PR as is and just run some local tests.

On my local machine

# First run (no local aws-sdk-go cache)
time ACK_GENERATE_CACHE_DIR=/tmp/gitest AWS_SDK_GO_VERSION=v1.38.60 make build-ack-generate build-controller SERVICE=ecr
building ack-generate ... ok.
Copying common custom resource definitions into ecr
Building Kubernetes API objects for ecr
Generating deepcopy code for ecr
Generating custom resource definitions for ecr
Building service controller for ecr
Generating RBAC manifests for ecr
Running gofmt against generated code for ecr
ACK_GENERATE_CACHE_DIR=/tmp/gitest AWS_SDK_GO_VERSION=v1.38.60 make     54,08s user 3,20s system 50% cpu 1:53,98 total

# Second run
time ACK_GENERATE_CACHE_DIR=/tmp/gitest AWS_SDK_GO_VERSION=v1.38.60 make build-ack-generate build-controller SERVICE=ecr
building ack-generate ... ok.
Copying common custom resource definitions into ecr
Building Kubernetes API objects for ecr
Generating deepcopy code for ecr
Generating custom resource definitions for ecr
Building service controller for ecr
Generating RBAC manifests for ecr
Running gofmt against generated code for ecr
ACK_GENERATE_CACHE_DIR=/tmp/gitest AWS_SDK_GO_VERSION=v1.38.60 make     8,04s user 1,27s system 176% cpu 5,264 total

/unhold

@ack-bot ack-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 30, 2021
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean, @a-hilaly. Good job! :)

@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 30, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Jun 30, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, vijtrip2

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,jaypipes,vijtrip2]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 9fec5f0 into aws-controllers-k8s:main Jun 30, 2021
ryansteakley added a commit to ryansteakley/code-generator that referenced this pull request Jul 1, 2021
# This is the 1st commit message:

add new field to pkg/generate/config.go so user can implement custom requiredFieldMissingFromReadOneInput

# This is the commit message aws-controllers-k8s#2:

Use `go-git` functionalities for common git operations (aws-controllers-k8s#108)

Part of aws-controllers-k8s/community#835

This patch updates all the helper functions to use `go-git` library
instead of having to call `os/exec.Command`/`os/exec.CombinedOutput` in
order to clone repository, fetch tags... These changes brings more
dependencies to our `go.mod` but in exchange it simplifies the way we
interact with git repositories and improves errors handling and
readability.

Future changes will also benefit from this patch, especially
conversation webhook generator that will need to checkout multiple
version tags.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
RedbackThomson pushed a commit to RedbackThomson/ack-code-generator that referenced this pull request Jul 8, 2021
…rs-k8s#108)

Part of aws-controllers-k8s/community#835

This patch updates all the helper functions to use `go-git` library
instead of having to call `os/exec.Command`/`os/exec.CombinedOutput` in
order to clone repository, fetch tags... These changes brings more
dependencies to our `go.mod` but in exchange it simplifies the way we
interact with git repositories and improves errors handling and
readability.

Future changes will also benefit from this patch, especially
conversation webhook generator that will need to checkout multiple
version tags.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants