From 50fbf5068fb0960b311f39e5312540600d23b116 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 17 Mar 2024 21:52:28 -0700 Subject: [PATCH] remotecache: fix missing CheckDescriptor method This method is needed by GHA cache backend to detect if Github deletes blobs from the cache because of storage caps. It got missing when Info() support was added. Signed-off-by: Tonis Tiigi (cherry picked from commit 5a8856de504aee00029286b24772f0b6cdae7b77) --- cache/remotecache/v1/chains.go | 9 +++++++++ cache/remotecache/v1/utils.go | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cache/remotecache/v1/chains.go b/cache/remotecache/v1/chains.go index a6916ebb9e66..644878340ce3 100644 --- a/cache/remotecache/v1/chains.go +++ b/cache/remotecache/v1/chains.go @@ -122,6 +122,8 @@ type DescriptorProviderPair struct { Provider content.Provider } +var _ withCheckDescriptor = DescriptorProviderPair{} + func (p DescriptorProviderPair) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) { return p.Provider.ReaderAt(ctx, desc) } @@ -156,6 +158,13 @@ func (p DescriptorProviderPair) SnapshotLabels(descs []ocispecs.Descriptor, inde return nil } +func (p DescriptorProviderPair) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error { + if cd, ok := p.Provider.(withCheckDescriptor); ok { + return cd.CheckDescriptor(ctx, desc) + } + return nil +} + // item is an implementation of a record in the cache chain. After validation, // normalization and marshalling into the cache config, the item results form // into the "layers", while the digests and the links form into the "records". diff --git a/cache/remotecache/v1/utils.go b/cache/remotecache/v1/utils.go index 213e670a61d2..01d44c90278f 100644 --- a/cache/remotecache/v1/utils.go +++ b/cache/remotecache/v1/utils.go @@ -12,6 +12,11 @@ import ( "github.com/pkg/errors" ) +type withCheckDescriptor interface { + // CheckDescriptor is additional method on Provider to check if the descriptor is available without opening the reader + CheckDescriptor(context.Context, ocispecs.Descriptor) error +} + // sortConfig sorts the config structure to make sure it is deterministic func sortConfig(cc *CacheConfig) { type indexedLayer struct { @@ -279,9 +284,7 @@ func marshalRemote(ctx context.Context, r *solver.Remote, state *marshalState) s return "" } - if cd, ok := r.Provider.(interface { - CheckDescriptor(context.Context, ocispecs.Descriptor) error - }); ok && len(r.Descriptors) > 0 { + if cd, ok := r.Provider.(withCheckDescriptor); ok && len(r.Descriptors) > 0 { for _, d := range r.Descriptors { if cd.CheckDescriptor(ctx, d) != nil { return ""