Skip to content

Commit

Permalink
Restore cached launch layers not found in appLayers
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
  • Loading branch information
pbusko and c0d1ngm0nk3y committed Apr 23, 2024
1 parent 37d6985 commit 1ae24b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/layer/metadata_restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 2 additions & 8 deletions internal/layer/metadata_restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/layer/testdata/cache_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1ae24b1

Please sign in to comment.