From 3629344e6e1b1b5a259285fee384b6bc0d47b4f9 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 31 Jul 2018 15:08:59 -0700 Subject: [PATCH 1/2] Ensure specifying an empty platform is treated as default The default platform had previously been provided using the empty string. This change ensures that the platforms field is always filled in correctly and empty string is properly interpreted. Signed-off-by: Derek McGowan --- client_opts.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client_opts.go b/client_opts.go index 56ec400c6..6e6198739 100644 --- a/client_opts.go +++ b/client_opts.go @@ -18,6 +18,7 @@ package containerd import ( "github.com/containerd/containerd/images" + "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/remotes" "google.golang.org/grpc" ) @@ -76,6 +77,9 @@ type RemoteOpt func(*Client, *RemoteContext) error // WithPlatform allows the caller to specify a platform to retrieve // content for func WithPlatform(platform string) RemoteOpt { + if platform == "" { + platform = platforms.Default() + } return func(_ *Client, c *RemoteContext) error { for _, p := range c.Platforms { if p == platform { From d64d8a06d549c33676b7ad7ac65e52e9731cf31a Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 31 Jul 2018 15:23:08 -0700 Subject: [PATCH 2/2] Use image constructor in client Replace manual image struct creation with the image constructor which is there to do just that. Signed-off-by: Derek McGowan --- client.go | 10 ++-------- container.go | 5 +---- import.go | 5 +---- task.go | 5 +---- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/client.go b/client.go index 3aa59327a..788a381d6 100644 --- a/client.go +++ b/client.go @@ -449,10 +449,7 @@ func (c *Client) GetImage(ctx context.Context, ref string) (Image, error) { if err != nil { return nil, err } - return &image{ - client: c, - i: i, - }, nil + return NewImage(c, i), nil } // ListImages returns all existing images @@ -463,10 +460,7 @@ func (c *Client) ListImages(ctx context.Context, filters ...string) ([]Image, er } images := make([]Image, len(imgs)) for i, img := range imgs { - images[i] = &image{ - client: c, - i: img, - } + images[i] = NewImage(c, img) } return images, nil } diff --git a/container.go b/container.go index 23f6d4db6..3c09b2dbc 100644 --- a/container.go +++ b/container.go @@ -173,10 +173,7 @@ func (c *container) Image(ctx context.Context) (Image, error) { if err != nil { return nil, errors.Wrapf(err, "failed to get image %s for container", r.Image) } - return &image{ - client: c.client, - i: i, - }, nil + return NewImage(c.client, i), nil } func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...NewTaskOpts) (_ Task, err error) { diff --git a/import.go b/import.go index 3148d240b..e4ac00cee 100644 --- a/import.go +++ b/import.go @@ -80,10 +80,7 @@ func (c *Client) Import(ctx context.Context, importer images.Importer, reader io imgrec = updated } - images = append(images, &image{ - client: c, - i: imgrec, - }) + images = append(images, NewImage(c, imgrec)) } return images, nil } diff --git a/task.go b/task.go index c9a86ffcd..750075f8d 100644 --- a/task.go +++ b/task.go @@ -458,10 +458,7 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag if im, err = t.client.ImageService().Create(ctx, im); err != nil { return nil, err } - return &image{ - client: t.client, - i: im, - }, nil + return NewImage(t.client, im), nil } // UpdateTaskInfo allows updated specific settings to be changed on a task