Remove extra roundtrip for checking schema1.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2019-08-09 18:47:40 -07:00
parent a7481289bb
commit d64fa3b6b8

View File

@ -94,17 +94,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 (
resolver = docker.NewResolver(docker.ResolverOptions{
Hosts: c.registryHosts(r.GetAuth()), Hosts: c.registryHosts(r.GetAuth()),
}) })
_, desc, err := resolver.Resolve(ctx, ref) isSchema1 bool
if err != nil { imageHandler containerdimages.HandlerFunc = func(_ context.Context,
return nil, errors.Wrapf(err, "failed to resolve image %q", ref) desc imagespec.Descriptor) ([]imagespec.Descriptor, error) {
if desc.MediaType == containerdimages.MediaTypeDockerSchema1Manifest {
isSchema1 = true
} }
// We have to check schema1 here, because after `Pull`, schema1 return nil, nil
// image has already been converted. }
isSchema1 := desc.MediaType == containerdimages.MediaTypeDockerSchema1Manifest )
image, err := c.client.Pull(ctx, ref, image, err := c.client.Pull(ctx, ref,
containerd.WithSchema1Conversion, containerd.WithSchema1Conversion,
containerd.WithResolver(resolver), containerd.WithResolver(resolver),
@ -112,6 +114,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)