-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: Pick up correct commit SHA when using annotated git tags (#4231) #4538
Conversation
reposerver/repository/repository.go
Outdated
@@ -163,6 +163,11 @@ func (s *Service) runRepoOperation( | |||
if err != nil { | |||
return nil, err | |||
} | |||
sha, err := gitClient.CommitSHA() |
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 am skeptical about this fix. gitClient.CommitSHA()
gives us the SHA of the HEAD which may not be the resolving tag is pointing to. I think we want to figure out what caused SHA resolution hehavior change since v1.4.2.
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 just tested it again to be sure, it is picking up the correct commit SHA for the specified tag even when HEAD points to a different SHA
I think it maybe using the state of the commit history from a particular revision so HEAD resolves to the same as the required commit
As for the behaviour change, from what I understand, the lsRemote
function just runs git ls-remote
's output, which is the list of all refs and tags with their SHAs. In this list, it seems the annotated tag's hash always appears before the SHA of the commit it points to (which is in the next line below it) and the current code just traverses the list and picks up the first one it sees, and ends up taking the hash of the tag instead of the commit SHA
if I had to guess, maybe the commit SHA showed up before the tag hash at some point and the ordering of the hashes present in the output of ls-remote may have changed recently (since the argocd code for this doesn't seem to have changed between 1.4.2 and the current version)
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.
IMHO, the only way to get the actual revision of the commit an annotated tag is pointing to is to checkout the tag, bringing the repository into detached HEAD state, and then resolve HEAD revision.
The checkout to the target revision is done a little later down the code path (
argo-cd/reposerver/repository/repository.go
Line 213 in 3ae1d13
_, err = checkoutRevision(gitClient, revision, log.WithField("repo", repo.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.
@jaanfis
The fix is working even when HEAD points to a different commit SHA
Seeing some strange behavior I haven't been able to explain yet though, CommitSHA()
seems to be running git rev-parse HEAD
but returning the correct commit SHA almost as if the correct revision of the repo is somehow already being checked out even before the actual call to checkoutRevision
happens, which happens later like you pointed out
Even when immediately before/after HEAD does get resolved to the actual HEAD in a different function call
There seems to be some kind of inconsistency between the api-server and repo-server here as to what HEAD actually points to
22:09:32 repo-server | DEBU[0039] revision 'v0.0.8' resolved to '95249be61b028d566c29d47b19e65c5603388a41'
22:09:32 repo-server | INFO[0039] git fetch origin --tags --force dir="/tmp/https:__github.com_jaideepr97_argocd-experiment" execID=OAWIY
22:09:32 repo-server | DEBU[0039] revision 'v0.0.8' resolved to '95249be61b028d566c29d47b19e65c5603388a41'
22:09:32 repo-server | INFO[0039] git rev-parse HEAD dir="/tmp/https:__github.com_jaideepr97_argocd-experiment" execID=W212M
22:09:32 repo-server | DEBU[0039] 632039659e542ed7de0c170a4fcc1c571b288fc0 duration=3.83898ms execID=W212M
22:09:32 repo-server | INFO[0039] app details cache miss: 632039659e542ed7de0c170a4fcc1c571b288fc0/&ApplicationSource{RepoURL:https://github.com/jaideepr97/ARGOCD-EXPERIMENT,Path:helm-guestbook,TargetRevision:v0.0.8,Helm:nil,Kustomize:nil,Ksonnet:nil,Directory:nil,Plugin:nil,Chart:,}
22:09:32 controller | INFO[0040] Successfully saved info of 1 clusters
22:09:32 api-server | 2020/10/15 22:09:32 proto: tag has too few fields: "-"
22:09:32 api-server | INFO[0039] received unary call /application.ApplicationService/Create grpc.method=Create grpc.request.claims=null grpc.request.content="%!v(PANIC=String method: reflect.Value.Bytes of non-byte slice)" grpc.service=application.ApplicationService grpc.start_time="2020-10-15T22:09:32Z" span.kind=server system=grpc
22:09:33 api-server | DEBU[0040] symbolic reference 'HEAD' (refs/heads/master) resolved to '401ea4c66bbd95c18eb3ed4d05912514cae83f30'
Here 401ea4c66bbd95c18eb3ed4d05912514cae83f30
is the actual HEAD, 95249be61b028d566c29d47b19e65c5603388a41
is the hash of the annotated tag and 632039659e542ed7de0c170a4fcc1c571b288fc0
is the commit I want
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.
@jaideepr97
It is a regression introduced in v1.6.0.
The revision returned from checkoutRevision() was ignored. This should fix it.
wtam2018@3b61354
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.
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.
Thank you for finding the root cause @wtam2018 , @jaideepr97 . Finally found why changes 4f49168 was implemented.
That was an attempt to fix caching for git tags. The problem is that we were using tag hash, returned by ls-remote
to load cached manifests:
argo-cd/reposerver/repository/repository.go
Line 169 in 15b0a6e
result, obj, err := getCached(revision, true) |
and then commit sha to store generated manifests in cache:
argo-cd/reposerver/repository/repository.go
Line 227 in 15b0a6e
return operation(appPath, gitClient.Root(), revision, signature) |
(operation
eventually uses revision
to store cache).
So repo-server was unable to property cache manifests for annotated tags and had to regenerate them again and again.
I think this PR re-introduced old bug again. @jaideepr97 I think we can fix it by adding one more parameter to operation
that holds ls-remote
result, so that operation
has both commitSHA and revision used to retrieve cache.
Codecov Report
@@ Coverage Diff @@
## master #4538 +/- ##
==========================================
+ Coverage 41.31% 41.34% +0.02%
==========================================
Files 124 124
Lines 16976 16976
==========================================
+ Hits 7014 7018 +4
+ Misses 8950 8948 -2
+ Partials 1012 1010 -2
Continue to review full report at Codecov.
|
…eing used to store and retrieve manifests in cache
reposerver/repository/repository.go
Outdated
@@ -145,7 +145,7 @@ func (s *Service) runRepoOperation( | |||
source *v1alpha1.ApplicationSource, | |||
verifyCommit bool, | |||
getCached func(revision string, firstInvocation bool) (bool, interface{}, error), | |||
operation func(appPath, repoRoot, revision, verifyResult string) (interface{}, error), | |||
operation func(appPath, repoRoot, commitSHA, revision, verifyResult string) (interface{}, error), |
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.
We might want to add some commment to describe the difference between these parameters. commitSHA
is a resolved SHA from a revision. It goes to the generated manifest. revision
is used as a key to manifest cache. I would probably rename revision
to cacheKey
.
…for cache usage, renamed revision to cacheKey
LGTM |
Thanks for the help and feedback! |
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.
LGTM. Thank you @jaideepr97 !
Checklist:
fixes: #4231
Argocd seems to be picking up the hash of the tag from the output of
ls-remote
rather than the commit SHA in case of annotated tags, this fix checks to see if the picked up revision matches the commit SHA or not, and replaces the tag hash with the commit SHA if not