-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Use mediatype helpers in more places #9155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f1cbc5f
da11969
5ab04ac
69034f7
cdba616
0ba5b4b
79acce4
8b10598
5518a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,17 +71,17 @@ func MakeRefKey(ctx context.Context, desc ocispec.Descriptor) string { | |
| } | ||
| } | ||
|
|
||
| switch mt := desc.MediaType; { | ||
| case mt == images.MediaTypeDockerSchema2Manifest || mt == ocispec.MediaTypeImageManifest: | ||
| switch { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dropped the |
||
| case images.IsManifestType(desc.MediaType): | ||
| return "manifest-" + key | ||
| case mt == images.MediaTypeDockerSchema2ManifestList || mt == ocispec.MediaTypeImageIndex: | ||
| case images.IsIndexType(desc.MediaType): | ||
| return "index-" + key | ||
| case images.IsLayerType(mt): | ||
| case images.IsLayerType(desc.MediaType): | ||
| return "layer-" + key | ||
| case images.IsKnownConfig(mt): | ||
| case images.IsKnownConfig(desc.MediaType): | ||
| return "config-" + key | ||
| default: | ||
| log.G(ctx).Warnf("reference for unknown type: %s", mt) | ||
| log.G(ctx).Warnf("reference for unknown type: %s", desc.MediaType) | ||
| return "unknown-" + key | ||
| } | ||
| } | ||
|
|
@@ -90,23 +90,21 @@ func MakeRefKey(ctx context.Context, desc ocispec.Descriptor) string { | |
| // discovered in a call to Dispatch. Use with ChildrenHandler to do a full | ||
| // recursive fetch. | ||
| func FetchHandler(ingester content.Ingester, fetcher Fetcher) images.HandlerFunc { | ||
| return func(ctx context.Context, desc ocispec.Descriptor) (subdescs []ocispec.Descriptor, err error) { | ||
| return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear to me why named returns were used here; after dropping the case scope this becomes an error (due to I've elected to drop this as everything becomes more clear with explicit returns in this otherwise trivial function. |
||
| ctx = log.WithLogger(ctx, log.G(ctx).WithFields(log.Fields{ | ||
| "digest": desc.Digest, | ||
| "mediatype": desc.MediaType, | ||
| "size": desc.Size, | ||
| })) | ||
|
|
||
| switch desc.MediaType { | ||
| case images.MediaTypeDockerSchema1Manifest: | ||
| if desc.MediaType == images.MediaTypeDockerSchema1Manifest { | ||
| return nil, fmt.Errorf("%v not supported", desc.MediaType) | ||
| default: | ||
| err := Fetch(ctx, ingester, fetcher, desc) | ||
| if errdefs.IsAlreadyExists(err) { | ||
| return nil, nil | ||
| } | ||
| return nil, err | ||
| } | ||
| err := Fetch(ctx, ingester, fetcher, desc) | ||
| if errdefs.IsAlreadyExists(err) { | ||
| return nil, nil | ||
| } | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -214,20 +212,18 @@ func PushContent(ctx context.Context, pusher Pusher, desc ocispec.Descriptor, st | |
| indexStack := []ocispec.Descriptor{} | ||
|
|
||
| filterHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { | ||
| switch desc.MediaType { | ||
| case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: | ||
| if images.IsManifestType(desc.MediaType) { | ||
| m.Lock() | ||
| manifests = append(manifests, desc) | ||
| m.Unlock() | ||
| return nil, images.ErrStopHandler | ||
| case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: | ||
| } else if images.IsIndexType(desc.MediaType) { | ||
| m.Lock() | ||
| indexStack = append(indexStack, desc) | ||
| m.Unlock() | ||
| return nil, images.ErrStopHandler | ||
| default: | ||
| return nil, nil | ||
| } | ||
| return nil, nil | ||
| }) | ||
|
|
||
| pushHandler := PushHandler(pusher, store) | ||
|
|
@@ -318,24 +314,16 @@ func FilterManifestByPlatformHandler(f images.HandlerFunc, m platforms.Matcher) | |
| return children, nil | ||
| } | ||
|
|
||
| var descs []ocispec.Descriptor | ||
| switch desc.MediaType { | ||
| case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: | ||
| if m.Match(*desc.Platform) { | ||
| descs = children | ||
| } else { | ||
| for _, child := range children { | ||
| if child.MediaType == images.MediaTypeDockerSchema2Config || | ||
| child.MediaType == ocispec.MediaTypeImageConfig { | ||
|
|
||
| descs = append(descs, child) | ||
| } | ||
| if images.IsManifestType(desc.MediaType) && !m.Match(*desc.Platform) { | ||
| var descs []ocispec.Descriptor | ||
| for _, child := range children { | ||
| if images.IsConfigType(child.MediaType) { | ||
| descs = append(descs, child) | ||
| } | ||
| } | ||
| default: | ||
| descs = children | ||
| return descs, nil | ||
| } | ||
| return descs, nil | ||
| return children, nil | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -350,10 +338,7 @@ func annotateDistributionSourceHandler(f images.HandlerFunc, provider content.In | |
|
|
||
| // Distribution source is only used for config or blob but may be inherited from | ||
| // a manifest or manifest list | ||
| switch desc.MediaType { | ||
| case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest, | ||
| images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: | ||
| default: | ||
| if !images.IsManifestType(desc.MediaType) && !images.IsIndexType(desc.MediaType) { | ||
| return children, nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function appears to have been copied more-or-less wholesale from
FetchHandlerinhandlers; my thoughts at https://github.com/containerd/containerd/pull/9155/files#r1339001829 apply equally here.