Skip to content

Commit 5a8856d

Browse files
committed
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 <[email protected]>
1 parent 6c0b576 commit 5a8856d

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

cache/remotecache/v1/chains.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ type DescriptorProviderPair struct {
122122
Provider content.Provider
123123
}
124124

125+
var _ withCheckDescriptor = DescriptorProviderPair{}
126+
125127
func (p DescriptorProviderPair) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
126128
return p.Provider.ReaderAt(ctx, desc)
127129
}
@@ -156,6 +158,13 @@ func (p DescriptorProviderPair) SnapshotLabels(descs []ocispecs.Descriptor, inde
156158
return nil
157159
}
158160

161+
func (p DescriptorProviderPair) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error {
162+
if cd, ok := p.Provider.(withCheckDescriptor); ok {
163+
return cd.CheckDescriptor(ctx, desc)
164+
}
165+
return nil
166+
}
167+
159168
// item is an implementation of a record in the cache chain. After validation,
160169
// normalization and marshalling into the cache config, the item results form
161170
// into the "layers", while the digests and the links form into the "records".

cache/remotecache/v1/utils.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15+
type withCheckDescriptor interface {
16+
// CheckDescriptor is additional method on Provider to check if the descriptor is available without opening the reader
17+
CheckDescriptor(context.Context, ocispecs.Descriptor) error
18+
}
19+
1520
// sortConfig sorts the config structure to make sure it is deterministic
1621
func sortConfig(cc *CacheConfig) {
1722
type indexedLayer struct {
@@ -279,9 +284,7 @@ func marshalRemote(ctx context.Context, r *solver.Remote, state *marshalState) s
279284
return ""
280285
}
281286

282-
if cd, ok := r.Provider.(interface {
283-
CheckDescriptor(context.Context, ocispecs.Descriptor) error
284-
}); ok && len(r.Descriptors) > 0 {
287+
if cd, ok := r.Provider.(withCheckDescriptor); ok && len(r.Descriptors) > 0 {
285288
for _, d := range r.Descriptors {
286289
if cd.CheckDescriptor(ctx, d) != nil {
287290
return ""

0 commit comments

Comments
 (0)