Skip to content

Commit

Permalink
fix: invalid revision in re-used manifest cache (argoproj#17874)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
alexmt authored Apr 17, 2024
1 parent b867c9e commit f91179f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions reposerver/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ func (c *Cache) GetManifests(revision string, appSrc *appv1.ApplicationSource, s
// The expected hash matches the actual hash, so remove the hash from the returned value
res.CacheEntryHash = ""

if res.ManifestResponse != nil {
// cached manifest response might be reused across different revisions, so we need to assume that the revision is the one we are looking for
res.ManifestResponse.Revision = revision
}

return nil
}

Expand Down
13 changes: 10 additions & 3 deletions reposerver/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,18 @@ func TestCache_GetManifests(t *testing.T) {
assert.Equal(t, ErrCacheMiss, err)
})
t.Run("expect cache hit", func(t *testing.T) {
err = cache.GetManifests("my-revision", &ApplicationSource{}, q.RefSources, q, "my-namespace", "", "my-app-label-key", "my-app-label-value", value, nil)
err = cache.SetManifests(
"my-revision1", &ApplicationSource{}, q.RefSources, q, "my-namespace", "", "my-app-label-key", "my-app-label-value",
&CachedManifestResponse{ManifestResponse: &apiclient.ManifestResponse{SourceType: "my-source-type", Revision: "my-revision2"}}, nil)
assert.NoError(t, err)
assert.Equal(t, &CachedManifestResponse{ManifestResponse: &apiclient.ManifestResponse{SourceType: "my-source-type"}}, value)

err = cache.GetManifests("my-revision1", &ApplicationSource{}, q.RefSources, q, "my-namespace", "", "my-app-label-key", "my-app-label-value", value, nil)
assert.NoError(t, err)

assert.Equal(t, "my-source-type", value.ManifestResponse.SourceType)
assert.Equal(t, "my-revision1", value.ManifestResponse.Revision)
})
mockCache.AssertCacheCalledTimes(t, &mocks.CacheCallCounts{ExternalSets: 1, ExternalGets: 8})
mockCache.AssertCacheCalledTimes(t, &mocks.CacheCallCounts{ExternalSets: 2, ExternalGets: 8})
}

func TestCache_GetAppDetails(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestGenerateManifests_K8SAPIResetCache(t *testing.T) {
ProjectSourceRepos: []string{"*"},
}

cachedFakeResponse := &apiclient.ManifestResponse{Manifests: []string{"Fake"}}
cachedFakeResponse := &apiclient.ManifestResponse{Manifests: []string{"Fake"}, Revision: mock.Anything}

err := service.cache.SetManifests(mock.Anything, &src, q.RefSources, &q, "", "", "", "", &cache.CachedManifestResponse{ManifestResponse: cachedFakeResponse}, nil)
assert.NoError(t, err)
Expand Down

0 comments on commit f91179f

Please sign in to comment.