Fix repository cache regression

If implemented this make sure we don't unload an index before caching it
during a chart build phase.

Signed-off-by: Soule BA <soule@weave.works>
This commit is contained in:
Soule BA 2022-06-05 23:24:06 +02:00
parent 9e3304144b
commit 0d4d78fc6b
No known key found for this signature in database
GPG Key ID: 4D40965192802994
3 changed files with 11 additions and 3 deletions

View File

@ -159,6 +159,14 @@ func TestHelmChartReconciler_Reconcile(t *testing.T) {
return obj.Status.LastHandledReconcileAt == "now"
}, timeout).Should(BeTrue())
// Check if the cache contains the index.
repoKey := client.ObjectKey{Name: repository.Name, Namespace: repository.Namespace}
err = testEnv.Get(ctx, repoKey, repository)
g.Expect(err).ToNot(HaveOccurred())
localPath := testStorage.LocalPath(*repository.GetArtifact())
_, found := testCache.Get(localPath)
g.Expect(found).To(BeTrue())
g.Expect(testEnv.Delete(ctx, obj)).To(Succeed())
// Wait for HelmChart to be deleted

View File

@ -103,6 +103,7 @@ var (
var (
testRegistryServer *registryClientTestServer
testCache *cache.Cache
)
func init() {
@ -246,7 +247,7 @@ func TestMain(m *testing.M) {
panic(fmt.Sprintf("Failed to start HelmRepositoryOCIReconciler: %v", err))
}
c := cache.New(5, 1*time.Second)
testCache = cache.New(5, 1*time.Second)
cacheRecorder := cache.MustMakeMetrics()
if err := (&HelmChartReconciler{
Client: testEnv,
@ -254,7 +255,7 @@ func TestMain(m *testing.M) {
Metrics: testMetricsH,
Getters: testGetters,
Storage: testStorage,
Cache: c,
Cache: testCache,
TTL: 1 * time.Second,
CacheRecorder: cacheRecorder,
}).SetupWithManager(testEnv); err != nil {

View File

@ -186,7 +186,6 @@ func (b *remoteChartBuilder) downloadFromRepository(remote *repository.ChartRepo
err = fmt.Errorf("could not load repository index for remote chart reference: %w", err)
return nil, &BuildError{Reason: ErrChartPull, Err: err}
}
defer remote.Unload()
// Get the current version for the RemoteReference
cv, err := remote.Get(remoteRef.Name, remoteRef.Version)