Skip to content

Commit d643f1d

Browse files
committed
images: only fetch the best matched manifest info
When client uses Pull action to pull image, it will limit the number of manifest as one. But Unpack action will call Manifest to traverse all the manifests including non-dowloaded one. If the platform has more than one manifest, the Pull with unpack action will fail. And also, there is no need to read non-best matched manifest. Therefore, the Manifest can do the sort earlier. Signed-off-by: Wei Fu <[email protected]>
1 parent f2b6c31 commit d643f1d

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

images/image.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type platformManifest struct {
142142
// this direction because this abstraction is not needed.`
143143
func Manifest(ctx context.Context, provider content.Provider, image ocispec.Descriptor, platform platforms.MatchComparer) (ocispec.Manifest, error) {
144144
var (
145+
limit = 1
145146
m []platformManifest
146147
wasIndex bool
147148
)
@@ -210,10 +211,22 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc
210211
}
211212
}
212213

214+
sort.SliceStable(descs, func(i, j int) bool {
215+
if descs[i].Platform == nil {
216+
return false
217+
}
218+
if descs[j].Platform == nil {
219+
return true
220+
}
221+
return platform.Less(*descs[i].Platform, *descs[j].Platform)
222+
})
223+
213224
wasIndex = true
214225

226+
if len(descs) > limit {
227+
return descs[:limit], nil
228+
}
215229
return descs, nil
216-
217230
}
218231
return nil, errors.Wrapf(errdefs.ErrNotFound, "unexpected media type %v for %v", desc.MediaType, desc.Digest)
219232
}), image); err != nil {
@@ -227,17 +240,6 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc
227240
}
228241
return ocispec.Manifest{}, err
229242
}
230-
231-
sort.SliceStable(m, func(i, j int) bool {
232-
if m[i].p == nil {
233-
return false
234-
}
235-
if m[j].p == nil {
236-
return true
237-
}
238-
return platform.Less(*m[i].p, *m[j].p)
239-
})
240-
241243
return *m[0].m, nil
242244
}
243245

0 commit comments

Comments
 (0)