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

fix: filter platforms when set metric ImageSize #134

Merged
merged 2 commits into from
May 12, 2023
Merged
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: 1 addition & 1 deletion pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (cvt *Converter) Convert(ctx context.Context, source, target string) (*Metr
return nil, errors.Wrap(err, "convert image")
}
metric.ConversionElapsed = time.Since(start)
if err := metric.SetTargetImageSize(ctx, cvt.provider.ContentStore(), desc); err != nil {
if err := metric.SetTargetImageSize(ctx, cvt, desc); err != nil {
return nil, errors.Wrap(err, "get target image size")
}
logger.Infof("converted image %s, elapse %s", target, metric.ConversionElapsed)
Expand Down
24 changes: 11 additions & 13 deletions pkg/converter/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ import (

"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

const (
MediaTypeDockerSchema2Manifest = "application/vnd.docker.distribution.manifest.v2+json"
MediaTypeDockerSchema2ManifestList = "application/vnd.docker.distribution.manifest.list.v2+json"
)

// Metric collected the metrics of conversion progress
type Metric struct {
// Total size of the source image with specified platforms in bytes
Expand All @@ -43,9 +39,9 @@ type Metric struct {
TargetPushElapsed time.Duration
}

func (metric *Metric) SetTargetImageSize(ctx context.Context, cs content.Store, desc *ocispec.Descriptor) error {
func (metric *Metric) SetTargetImageSize(ctx context.Context, cvt *Converter, desc *ocispec.Descriptor) error {
var err error
metric.TargetImageSize, err = metric.imageSize(ctx, cs, desc)
metric.TargetImageSize, err = metric.imageSize(ctx, cvt.provider.ContentStore(), desc, cvt.platformMC)
return err
}

Expand All @@ -54,15 +50,17 @@ func (metric *Metric) SetSourceImageSize(ctx context.Context, cvt *Converter, so
if err != nil {
return err
}
metric.SourceImageSize, err = metric.imageSize(ctx, cvt.provider.ContentStore(), image)
return err
if metric.SourceImageSize, err = metric.imageSize(ctx, cvt.provider.ContentStore(), image, cvt.platformMC); err != nil {
return err
}
return nil
Desiki-high marked this conversation as resolved.
Show resolved Hide resolved
}

func (metric *Metric) imageSize(ctx context.Context, cs content.Store, image *ocispec.Descriptor) (int64, error) {
func (metric *Metric) imageSize(ctx context.Context, cs content.Store, image *ocispec.Descriptor, platformMC platforms.MatchComparer) (int64, error) {
var imageSize int64
switch image.MediaType {
case ocispec.MediaTypeImageIndex, MediaTypeDockerSchema2ManifestList:
manifests, err := images.ChildrenHandler(cs)(ctx, *image)
case ocispec.MediaTypeImageIndex, images.MediaTypeDockerSchema2ManifestList:
manifests, err := images.FilterPlatforms(images.ChildrenHandler(cs), platformMC)(ctx, *image)
if err != nil {
return imageSize, err
}
Expand All @@ -75,7 +73,7 @@ func (metric *Metric) imageSize(ctx context.Context, cs content.Store, image *oc
imageSize += desc.Size
}
}
case ocispec.MediaTypeImageManifest, MediaTypeDockerSchema2Manifest:
case ocispec.MediaTypeImageManifest, images.MediaTypeDockerSchema2Manifest:
children, err := images.ChildrenHandler(cs)(ctx, *image)
if err != nil {
return imageSize, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/nydus/nydus.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func New(cfg map[string]string, platformMC platforms.MatchComparer) (*Driver, er
// For compatibility of older configuration.
fsVersion = cfg["rafs_version"]
if fsVersion == "" {
fsVersion = "5"
fsVersion = "6"
}
}
compressor := cfg["compressor"]
Expand Down