fetch the content related to the passed in reference into the blob store and appends the provided c8dimages.Handlers There is no need to use remotes.FetchHandler since it already gets set
(ctx context.Context, ref reference.Named, auth *registry.AuthConfig, out progress.Output, metaHeader http.Header, handlers ...c8dimages.Handler)
| 60 | // fetch the content related to the passed in reference into the blob store and appends the provided c8dimages.Handlers |
| 61 | // There is no need to use remotes.FetchHandler since it already gets set |
| 62 | func (pm *Manager) fetch(ctx context.Context, ref reference.Named, auth *registry.AuthConfig, out progress.Output, metaHeader http.Header, handlers ...c8dimages.Handler) error { |
| 63 | // We need to make sure we have a domain on the reference |
| 64 | withDomain, err := reference.ParseNormalizedNamed(ref.String()) |
| 65 | if err != nil { |
| 66 | return errors.Wrap(err, "error parsing plugin image reference") |
| 67 | } |
| 68 | |
| 69 | // Make sure we can authenticate the request since the auth scope for plugin repos is different than a normal repo. |
| 70 | ctx = docker.WithScope(ctx, scope(ref, false)) |
| 71 | |
| 72 | // Make sure the fetch handler knows how to set a ref key for the plugin media type. |
| 73 | // Without this the ref key is "unknown" and we see a nasty warning message in the logs |
| 74 | ctx = remotes.WithMediaTypeKeyPrefix(ctx, mediaTypePluginConfig, "docker-plugin") |
| 75 | |
| 76 | resolver, err := pm.newResolver(ctx, nil, auth, metaHeader, false) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | resolved, desc, err := resolver.Resolve(ctx, withDomain.String()) |
| 81 | if err != nil { |
| 82 | // This is backwards compatible with older versions of the distribution registry. |
| 83 | // The containerd client will add it's own accept header as a comma separated list of supported manifests. |
| 84 | // This is perfectly fine, unless you are talking to an older registry which does not split the comma separated list, |
| 85 | // so it is never able to match a media type and it falls back to schema1 (yuck) and fails because our manifest the |
| 86 | // fallback does not support plugin configs... |
| 87 | log.G(ctx).WithError(err).WithField("ref", withDomain).Debug("Error while resolving reference, falling back to backwards compatible accept header format") |
| 88 | headers := http.Header{} |
| 89 | headers.Add("Accept", c8dimages.MediaTypeDockerSchema2Manifest) |
| 90 | headers.Add("Accept", c8dimages.MediaTypeDockerSchema2ManifestList) |
| 91 | headers.Add("Accept", ocispec.MediaTypeImageManifest) |
| 92 | headers.Add("Accept", ocispec.MediaTypeImageIndex) |
| 93 | resolver, _ = pm.newResolver(ctx, nil, auth, headers, false) |
| 94 | if resolver != nil { |
| 95 | resolved, desc, err = resolver.Resolve(ctx, withDomain.String()) |
| 96 | if err != nil { |
| 97 | log.G(ctx).WithError(err).WithField("ref", withDomain).Debug("Failed to resolve reference after falling back to backwards compatible accept header format") |
| 98 | } |
| 99 | } |
| 100 | if err != nil { |
| 101 | return errors.Wrap(err, "error resolving plugin reference") |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | fetcher, err := resolver.Fetcher(ctx, resolved) |
| 106 | if err != nil { |
| 107 | return errors.Wrap(err, "error creating plugin image fetcher") |
| 108 | } |
| 109 | |
| 110 | fp := withFetchProgress(pm.blobStore, out, ref) |
| 111 | handlers = append([]c8dimages.Handler{fp, remotes.FetchHandler(pm.blobStore, fetcher)}, handlers...) |
| 112 | return c8dimages.Dispatch(ctx, c8dimages.Handlers(handlers...), nil, desc) |
| 113 | } |
| 114 | |
| 115 | // applyLayer makes an c8dimages.HandlerFunc which applies a fetched image rootfs layer to a directory. |
| 116 | // |
no test coverage detected