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

refactor(controller): overhaul git repo interfaces #2483

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

krancour
Copy link
Member

This is a bit of an overhaul of the internal/controller/git package that kills a few birds with one stone.

Promotion directives will require support for bare repos with multiple working trees associated with them.

The capabilities of a normal repo with a single working tree vs a bare repo vs a working tree associated with a bare repo are all a little different. It made sense to expose three distinct interfaces -- Repo, BareRepo, and WorkTree. (The Repo interface is a superset of the WorkTree interface while the BareRepo interface lacks all the capabilities of a WorkTree, but has some distinct capabilities like AddWorkTree or RemoveWorkTree.)

Git-based promotion directives will rely heavily on these new interfaces. A clone directive may create a bare clone with one or more working trees.

Subsequent directives, such as commit and push will require the ability to interact with bare repos and working trees that already exist in the FS. Thus, obtaining interfaces for existing repos and working trees is another new capability introduced by this PR.

Directives will also introduce the possibility that, for instance, pushing a commit occurs long after cloning a repo, and in the intervening time, the credentials used to clone may have expired and will not be useful for pushing. This introduces a requirement that when obtaining interfaces for repos or working trees that already exist on the file system, the credentials must be refreshed.

This PR also takes #2400 into account. I anticipate the image-hardening effort will soon result in Kargo images that lack a shell. Kargo Render has already been through this in akuity/kargo-render#297. The store credential helper that we previously relied on requires a shell to function properly. So while already ensuring credentials are refreshed whenever an interface is obtained for an existing repo or working tree from the file system, I decided it was advisable to cut over to the custom credential helper strategy that Kargo Render also uses now.

A couple noteworthy aspects of this PR:

  • The existing Repo interface barely breaks, so the impact to existing code is minimal.

  • The implementation of existing functionality barely changes.

  • The PR adds new tests where none existed before to aid in asserting that nothing breaks.

  • I've also executed a battery of e2e tests against these changes and everything checks out.

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
@krancour krancour self-assigned this Aug 30, 2024
@krancour krancour requested a review from a team as a code owner August 30, 2024 23:08
Copy link

netlify bot commented Aug 30, 2024

Deploy Preview for docs-kargo-akuity-io canceled.

Name Link
🔨 Latest commit b4a47b0
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-akuity-io/deploys/66d72cf66fc7110008409804

@krancour krancour added this to the v0.9.0 milestone Aug 30, 2024
@krancour krancour changed the title overhaul the git package refactor(controller): overhaul the git package Aug 30, 2024
@krancour krancour changed the title refactor(controller): overhaul the git package refactor(controller): overhaul git repo interfaces Aug 30, 2024
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 46.73721% with 302 lines in your changes missing coverage. Please review.

Project coverage is 48.79%. Comparing base (bbd3fdf) to head (b4a47b0).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
internal/controller/git/work_tree.go 35.26% 135 Missing and 21 partials ⚠️
internal/controller/git/base_repo.go 54.62% 38 Missing and 16 partials ⚠️
internal/controller/git/bare_repo.go 63.49% 25 Missing and 21 partials ⚠️
internal/controller/git/repo.go 51.47% 18 Missing and 15 partials ⚠️
cmd/credential-helper/main.go 0.00% 6 Missing ⚠️
internal/controller/promotion/git.go 0.00% 4 Missing ⚠️
internal/controller/promotion/pullrequest.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2483      +/-   ##
==========================================
+ Coverage   48.27%   48.79%   +0.51%     
==========================================
  Files         246      250       +4     
  Lines       17739    17969     +230     
==========================================
+ Hits         8564     8768     +204     
+ Misses       8749     8721      -28     
- Partials      426      480      +54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

This is excellent! 🔥🔥🔥

}
// The root of the bare repo will be three levels up from the path returned
// by git rev-parse --git-dir
repoPath := filepath.Join(strings.TrimSpace(string(res)), "..", "..", "..", "repo")
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: this feels prone to errors.

Copy link
Member Author

@krancour krancour Sep 2, 2024

Choose a reason for hiding this comment

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

I didn't love this either and I'd be happy to take any suggestion you might have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored this in b4a47b0

Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
@krancour krancour added this pull request to the merge queue Sep 3, 2024
Merged via the queue into akuity:main with commit 575b00c Sep 3, 2024
16 of 17 checks passed
@krancour krancour deleted the krancour/overhauled-git-pkg branch September 3, 2024 15:56
krancour added a commit to krancour/kargo that referenced this pull request Sep 3, 2024
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants