From 1ae24b1e0d16e756a6f0c595d1e96953cf403c96 Mon Sep 17 00:00:00 2001 From: Pavel Busko Date: Tue, 23 Apr 2024 14:26:54 +0200 Subject: [PATCH] Restore cached launch layers not found in appLayers Co-authored-by: Ralf Pannemans Co-authored-by: Pavel Busko --- internal/layer/metadata_restorer.go | 4 ++-- internal/layer/metadata_restorer_test.go | 10 ++-------- internal/layer/testdata/cache_metadata.json | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/layer/metadata_restorer.go b/internal/layer/metadata_restorer.go index f33e0e17e..b86d066c5 100644 --- a/internal/layer/metadata_restorer.go +++ b/internal/layer/metadata_restorer.go @@ -113,8 +113,8 @@ func (r *DefaultMetadataRestorer) restoreLayerMetadata(layerSHAStore SHAStore, a r.Logger.Debugf("Not restoring %q from cache, marked as cache=false", identifier) continue } - // If launch=true, the metadata was restored from the app image or the layer is stale. - if layer.Launch { + // If launch=true, the metadata was restored from the appLayers if present. + if _, ok := appLayers[layerName]; ok && layer.Launch { r.Logger.Debugf("Not restoring %q from cache, marked as launch=true", identifier) continue } diff --git a/internal/layer/metadata_restorer_test.go b/internal/layer/metadata_restorer_test.go index aec91d373..5b3507eb8 100644 --- a/internal/layer/metadata_restorer_test.go +++ b/internal/layer/metadata_restorer_test.go @@ -136,6 +136,8 @@ func testLayerMetadataRestorer(t *testing.T, when spec.G, it spec.S) { {"no.cache.buildpack/some-layer.toml", "[metadata]\n some-layer-key = \"some-layer-value\""}, // Cache-image-only layers. {"metadata.buildpack/cache.toml", "[metadata]\n cache-key = \"cache-value\""}, + // Cached launch layers not in app + {"metadata.buildpack/launch-cache-not-in-app.toml", "[metadata]\n cache-only-key = \"cache-only-value\"\n launch-cache-key = \"cache-specific-value\""}, } { got := h.MustReadFile(t, filepath.Join(layerDir, data.name)) h.AssertStringContains(t, string(got), data.want) @@ -186,14 +188,6 @@ func testLayerMetadataRestorer(t *testing.T, when spec.G, it spec.S) { h.AssertPathDoesNotExist(t, filepath.Join(layerDir, "no.group.buildpack")) }) - it("does not restore launch=true layer metadata", func() { - err := layerMetadataRestorer.Restore(buildpacks, layersMetadata, cacheMetadata, layerSHAStore) - h.AssertNil(t, err) - - h.AssertPathDoesNotExist(t, filepath.Join(layerDir, "metadata.buildpack", "launch-cache-not-in-app.toml")) - h.AssertPathDoesNotExist(t, filepath.Join(layerDir, "metadata.buildpack", "launch-cache-not-in-app.sha")) - }) - it("does not restore cache=false layer metadata", func() { err := layerMetadataRestorer.Restore(buildpacks, layersMetadata, cacheMetadata, layerSHAStore) h.AssertNil(t, err) diff --git a/internal/layer/testdata/cache_metadata.json b/internal/layer/testdata/cache_metadata.json index cc982aa90..a60ee35a1 100644 --- a/internal/layer/testdata/cache_metadata.json +++ b/internal/layer/testdata/cache_metadata.json @@ -36,7 +36,7 @@ "launch": true, "sha": "launch-cache-old-sha" }, - "launch-cache-not-in-app": { + "launch-cache-not-in-app": { "cache": true, "data": { "launch-cache-key": "cache-specific-value",