-
Notifications
You must be signed in to change notification settings - Fork 135
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
Conversation
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
✅ Deploy Preview for docs-kargo-akuity-io canceled.
|
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent! 🔥🔥🔥
internal/controller/git/work_tree.go
Outdated
} | ||
// 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
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.