Skip to content
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

image: fix image.Manifest compatibility for checkpoint image #9082

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func (c *container) Checkpoint(ctx context.Context, ref string, opts ...Checkpoi
Versioned: ver.Versioned{
SchemaVersion: 2,
},
MediaType: ocispec.MediaTypeImageIndex,
Annotations: make(map[string]string),
}
copts := &options.CheckpointOptions{
Expand Down Expand Up @@ -377,6 +378,7 @@ func (c *container) Checkpoint(ctx context.Context, ref string, opts ...Checkpoi
if err != nil {
return nil, err
}
desc.Annotations = index.Annotations
i := images.Image{
Name: ref,
Target: desc,
Expand Down
33 changes: 28 additions & 5 deletions images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"path"
"sort"
"time"

Expand Down Expand Up @@ -207,6 +208,9 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc

var descs []ocispec.Descriptor
for _, d := range idx.Manifests {
if !IsManifestType(d.MediaType) {
continue
}
if d.Platform == nil || platform.Match(*d.Platform) {
descs = append(descs, d)
}
Expand All @@ -229,7 +233,7 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc
}
return descs, nil
}
return nil, fmt.Errorf("unexpected media type %v for %v: %w", desc.MediaType, desc.Digest, errdefs.ErrNotFound)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know why return error here

return nil, ErrSkipDesc
}), image); err != nil {
return ocispec.Manifest{}, err
}
Expand Down Expand Up @@ -259,10 +263,11 @@ func Config(ctx context.Context, provider content.Provider, image ocispec.Descri

// Platforms returns one or more platforms supported by the image.
func Platforms(ctx context.Context, provider content.Provider, image ocispec.Descriptor) ([]ocispec.Platform, error) {
var platformSpecs []ocispec.Platform
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
platformSpecMap := make(map[string]ocispec.Platform)
err := Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
if desc.Platform != nil {
platformSpecs = append(platformSpecs, *desc.Platform)
pk := makePlatformKey(*desc.Platform)
platformSpecMap[pk] = *desc.Platform
return nil, ErrSkipDesc
}

Expand All @@ -272,10 +277,28 @@ func Platforms(ctx context.Context, provider content.Provider, image ocispec.Des
if err != nil {
return nil, err
}
platformSpecs = append(platformSpecs, imagePlatform)
pk := makePlatformKey(imagePlatform)
platformSpecMap[pk] = imagePlatform
}
return nil, nil
}), ChildrenHandler(provider)), image)
if err != nil {
return nil, err
}

platformSpecs := make([]ocispec.Platform, 0, len(platformSpecMap))
for _, v := range platformSpecMap {
platformSpecs = append(platformSpecs, v)
}
return platformSpecs, nil
}

func makePlatformKey(platform ocispec.Platform) string {
if platform.OS == "" {
return "unknown"
}

return path.Join(platform.OS, platform.Architecture, platform.OSVersion, platform.Variant)
}

// Check returns nil if the all components of an image are available in the
Expand Down
1 change: 1 addition & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
Versioned: is.Versioned{
SchemaVersion: 2,
},
MediaType: v1.MediaTypeImageIndex,
Annotations: make(map[string]string),
}
if err := t.checkpointTask(ctx, &index, request); err != nil {
Expand Down