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

converter: move NoOptimize flag from optimizer to converter #199

Merged
merged 1 commit into from
Dec 16, 2020
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
10 changes: 5 additions & 5 deletions cmd/ctr-remote/commands/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ var OptimizeCommand = cli.Command{
}
}()

noOptimize := context.Bool("no-optimize")
optimizerOpts := &optimizer.Opts{
NoOptimize: context.Bool("no-optimize"),
Reuse: context.Bool("reuse"),
Period: time.Duration(context.Int("period")) * time.Second,
Reuse: context.Bool("reuse"),
Period: time.Duration(context.Int("period")) * time.Second,
}

// Convert and push the image
Expand All @@ -209,13 +209,13 @@ var OptimizeCommand = cli.Command{
return err
}
p := platforms.DefaultSpec()
dstImage, err := converter.ConvertImage(ctx, optimizerOpts, srcImage, &p, tf, opts...)
dstImage, err := converter.ConvertImage(ctx, noOptimize, optimizerOpts, srcImage, &p, tf, opts...)
if err != nil {
return err
}
return dstIO.WriteImage(dstImage)
}
dstIndex, err := converter.ConvertIndex(ctx, optimizerOpts, srcIndex, platform, tf, opts...)
dstIndex, err := converter.ConvertIndex(ctx, noOptimize, optimizerOpts, srcIndex, platform, tf, opts...)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
"golang.org/x/sync/errgroup"
)

func ConvertIndex(ctx gocontext.Context, opts *optimizer.Opts, srcIndex regpkg.ImageIndex, platform *spec.Platform, tf *tempfiles.TempFiles, runopts ...sampler.Option) (regpkg.ImageIndex, error) {
func ConvertIndex(ctx gocontext.Context, noOptimize bool, opts *optimizer.Opts, srcIndex regpkg.ImageIndex, platform *spec.Platform, tf *tempfiles.TempFiles, runopts ...sampler.Option) (regpkg.ImageIndex, error) {
var addendums []mutate.IndexAddendum
manifest, err := srcIndex.IndexManifest()
if err != nil {
Expand All @@ -67,7 +67,7 @@ func ConvertIndex(ctx gocontext.Context, opts *optimizer.Opts, srcIndex regpkg.I
return nil, err
}
cctx := log.WithLogger(ctx, log.G(ctx).WithField("platform", platforms.Format(p)))
dstImg, err := ConvertImage(cctx, opts, srcImg, &p, tf, runopts...)
dstImg, err := ConvertImage(cctx, noOptimize, opts, srcImg, &p, tf, runopts...)
if err != nil {
return nil, err
}
Expand All @@ -89,14 +89,14 @@ func ConvertIndex(ctx gocontext.Context, opts *optimizer.Opts, srcIndex regpkg.I
return mutate.AppendManifests(empty.Index, addendums...), nil
}

func ConvertImage(ctx gocontext.Context, opts *optimizer.Opts, srcImg regpkg.Image, platform *spec.Platform, tf *tempfiles.TempFiles, runopts ...sampler.Option) (dstImg regpkg.Image, _ error) {
func ConvertImage(ctx gocontext.Context, noOptimize bool, opts *optimizer.Opts, srcImg regpkg.Image, platform *spec.Platform, tf *tempfiles.TempFiles, runopts ...sampler.Option) (dstImg regpkg.Image, _ error) {
// The order of the list is base layer first, top layer last.
layers, err := srcImg.Layers()
if err != nil {
return nil, errors.Wrap(err, "failed to get image layers")
}
addendums := make([]mutate.Addendum, len(layers))
if opts.NoOptimize || !platforms.NewMatcher(platforms.DefaultSpec()).Match(*platform) {
if noOptimize || !platforms.NewMatcher(platforms.DefaultSpec()).Match(*platform) {
// Do not run the optimization container if the option requires it or
// the source image doesn't match to the platform where this command runs on.
log.G(ctx).Warn("Platform mismatch or optimization disabled; converting without optimization")
Expand Down
5 changes: 2 additions & 3 deletions converter/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ import (
)

type Opts struct {
NoOptimize bool
Reuse bool
Period time.Duration
Reuse bool
Period time.Duration
}

func Optimize(ctx gocontext.Context, opts *Opts, srcImg regpkg.Image, tf *tempfiles.TempFiles, samplerOpts ...sampler.Option) ([]mutate.Addendum, error) {
Expand Down