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

git: add a cache based on bundles #380

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

cdevienne
Copy link
Contributor

The cache strategy is simpler than the one I did for mercurial, and a little less efficient (it is slower).
But it is solid, and avoids a cumbersome refactoring of the fetcher.

@cdevienne
Copy link
Contributor Author

Hello @Zebradil,
Any chance this PR gets reviewed soon?
Thanks!

@Zebradil
Copy link
Member

Hey @cdevienne, sorry for the delay. As I'm currently not allowed to approve workflow runs on my own, I was waiting for the checks to be completed. But apparently, checks are not emitting any notifications upon completion, so this PR fell out of my sight. I'll check it out today or tomorrow.

Copy link
Member

@Zebradil Zebradil left a comment

Choose a reason for hiding this comment

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

First of all, many thanks for bringing this topic into attention and filing this PR!

The idea of using bundle seems okay. However, I have a couple of questions about it:

  • Did you consider maintaining a working copy in the cache instead of a bundle? (Earlier we had a discussion about the cache size. I see that the bundle approach allows to keep the cache size under control, which is hard when using the clone approach. But are there any other considerations?)
  • How does it work when history of a remote git repo gets rewritten (with git push --force, for example)?

Apart from that I left a few code-related comments. These suggestions should make the code a little more straightforward and easier to change in the future.

@joaopapereira Another thing I noticed is that now the vendir sync output can be quite mouthful, as it prints all refs in the repo being synced two times (in addition to the output of git fetch origin we can see in the main version of vendir).

UPD: This is not an issue of this PR, it is how git command runner works in vendir: it prints full output of a command. I'm not sure how to go about that. Maybe we should make verbosity level configurable in the future.

pkg/vendir/fetch/git/sync.go Outdated Show resolved Hide resolved
pkg/vendir/fetch/git/sync.go Outdated Show resolved Hide resolved
pkg/vendir/fetch/git/sync.go Outdated Show resolved Hide resolved
pkg/vendir/fetch/git/sync.go Outdated Show resolved Hide resolved
Signed-off-by: Christophe de Vienne <[email protected]>
Signed-off-by: Christophe de Vienne <[email protected]>
This allow to keep the Sync() signature as it was previously

Signed-off-by: Christophe de Vienne <[email protected]>
@cdevienne
Copy link
Contributor Author

cdevienne commented Jun 20, 2024

  • Did you consider maintaining a working copy in the cache instead of a bundle? (Earlier we had a discussion about the cache size. I see that the bundle approach allows to keep the cache size under control, which is hard when using the clone approach. But are there any other considerations?)

Yes I did, but it requires a bigger refactoring of the fetch code, and a deeper knowledge of git.
The approach I chose is very safe, and has no corner case I can think of.

  • How does it work when history of a remote git repo gets rewritten (with git push --force, for example)?

Then the git fetch would get all the new commits and cache a new updated bundle.

UPD: This is not an issue of this PR, it is how git command runner works in vendir: it prints full output of a command. I'm not sure how to go about that. Maybe we should make verbosity level configurable in the future.

Yes that would be nice.

Copy link
Member

@Zebradil Zebradil left a comment

Choose a reason for hiding this comment

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

LGTM,

except the fact that the public interface is changed (new argument to Retrieve). However, to me it's a minor issue, as I don't think that it'll bring any problems to users.

@joaopapereira could you take a look as well?

@joaopapereira
Copy link
Member

@joaopapereira Another thing I noticed is that now the vendir sync output can be quite mouthful, as it prints all refs in the repo being synced two times (in addition to the output of git fetch origin we can see in the main version of vendir).

UPD: This is not an issue of this PR, it is how git command runner works in vendir: it prints full output of a command. I'm not sure how to go about that. Maybe we should make verbosity level configurable in the future.

do you want to create an issue with that?

@joaopapereira
Copy link
Member

I will try to review it next week

@joaopapereira
Copy link
Member

The PR looks good, is there any way we can have some tests around the caching?

Signed-off-by: Christophe de Vienne <[email protected]>
@cdevienne
Copy link
Contributor Author

I added a basic test to prove it unbundles from the cache.

@Zebradil
Copy link
Member

@joaopapereira Another thing I noticed is that now the vendir sync output can be quite mouthful, as it prints all refs in the repo being synced two times (in addition to the output of git fetch origin we can see in the main version of vendir).
UPD: This is not an issue of this PR, it is how git command runner works in vendir: it prints full output of a command. I'm not sure how to go about that. Maybe we should make verbosity level configurable in the future.

do you want to create an issue with that?

Good idea. #387

Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

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

Added some comments to the test, just stylistic. When that is fixed I think we can merge the PR.

test/e2e/git_test.go Outdated Show resolved Hide resolved
test/e2e/git_test.go Outdated Show resolved Hide resolved
test/e2e/git_test.go Outdated Show resolved Hide resolved
test/e2e/git_test.go Outdated Show resolved Hide resolved
Comment on lines 154 to 156
if out, err := exec.Command("tar", "xzvf", "assets/git-repo-signed/asset.tgz", "-C", gitSrcPath).CombinedOutput(); err != nil {
t.Fatalf("Unpacking git-repo-signed asset: %s (output: '%s')", err, out)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if out, err := exec.Command("tar", "xzvf", "assets/git-repo-signed/asset.tgz", "-C", gitSrcPath).CombinedOutput(); err != nil {
t.Fatalf("Unpacking git-repo-signed asset: %s (output: '%s')", err, out)
}
out, err := exec.Command("tar", "xzvf", "assets/git-repo-signed/asset.tgz", "-C", gitSrcPath).CombinedOutput()
require.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, but kept the custom message

Signed-off-by: Christophe de Vienne <[email protected]>
Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

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

LGTM

@joaopapereira joaopapereira merged commit 5743fa5 into carvel-dev:develop Jun 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants