Merge pull request #1232 from Random-Liu/avoid-schema1-roundtrip

Remove extra roundtrip for checking schema1.
This commit is contained in:
Lantao Liu 2019-08-10 10:25:46 -07:00 committed by GitHub
commit fd6c732cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,17 +93,19 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
if ref != imageRef { if ref != imageRef {
log.G(ctx).Debugf("PullImage using normalized image ref: %q", ref) log.G(ctx).Debugf("PullImage using normalized image ref: %q", ref)
} }
resolver := docker.NewResolver(docker.ResolverOptions{ var (
Hosts: c.registryHosts(r.GetAuth()), resolver = docker.NewResolver(docker.ResolverOptions{
}) Hosts: c.registryHosts(r.GetAuth()),
_, desc, err := resolver.Resolve(ctx, ref) })
if err != nil { isSchema1 bool
return nil, errors.Wrapf(err, "failed to resolve image %q", ref) imageHandler containerdimages.HandlerFunc = func(_ context.Context,
} desc imagespec.Descriptor) ([]imagespec.Descriptor, error) {
// We have to check schema1 here, because after `Pull`, schema1 if desc.MediaType == containerdimages.MediaTypeDockerSchema1Manifest {
// image has already been converted. isSchema1 = true
isSchema1 := desc.MediaType == containerdimages.MediaTypeDockerSchema1Manifest }
return nil, nil
}
)
image, err := c.client.Pull(ctx, ref, image, err := c.client.Pull(ctx, ref,
containerd.WithSchema1Conversion, containerd.WithSchema1Conversion,
containerd.WithResolver(resolver), containerd.WithResolver(resolver),
@ -111,6 +113,7 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
containerd.WithPullUnpack, containerd.WithPullUnpack,
containerd.WithPullLabel(imageLabelKey, imageLabelValue), containerd.WithPullLabel(imageLabelKey, imageLabelValue),
containerd.WithMaxConcurrentDownloads(c.config.MaxConcurrentDownloads), containerd.WithMaxConcurrentDownloads(c.config.MaxConcurrentDownloads),
containerd.WithImageHandler(imageHandler),
) )
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to pull and unpack image %q", ref) return nil, errors.Wrapf(err, "failed to pull and unpack image %q", ref)