Support configurable default platform in the client.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
b039c39186
commit
555cb31fd9
@ -99,6 +99,12 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
c.runtime = defaults.DefaultRuntime
|
c.runtime = defaults.DefaultRuntime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if copts.defaultPlatform != nil {
|
||||||
|
c.platform = copts.defaultPlatform
|
||||||
|
} else {
|
||||||
|
c.platform = platforms.Default()
|
||||||
|
}
|
||||||
|
|
||||||
if copts.services != nil {
|
if copts.services != nil {
|
||||||
c.services = *copts.services
|
c.services = *copts.services
|
||||||
}
|
}
|
||||||
@ -193,6 +199,7 @@ type Client struct {
|
|||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
runtime string
|
runtime string
|
||||||
defaultns string
|
defaultns string
|
||||||
|
platform platforms.MatchComparer
|
||||||
connector func() (*grpc.ClientConn, error)
|
connector func() (*grpc.ClientConn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type clientOpts struct {
|
type clientOpts struct {
|
||||||
defaultns string
|
defaultns string
|
||||||
defaultRuntime string
|
defaultRuntime string
|
||||||
services *services
|
defaultPlatform platforms.MatchComparer
|
||||||
dialOptions []grpc.DialOption
|
services *services
|
||||||
timeout time.Duration
|
dialOptions []grpc.DialOption
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientOpt allows callers to set options on the containerd client
|
// ClientOpt allows callers to set options on the containerd client
|
||||||
@ -55,6 +56,14 @@ func WithDefaultRuntime(rt string) ClientOpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithDefaultPlatform sets the default platform matcher on the client
|
||||||
|
func WithDefaultPlatform(platform platforms.MatchComparer) ClientOpt {
|
||||||
|
return func(c *clientOpts) error {
|
||||||
|
c.defaultPlatform = platform
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithDialOpts allows grpc.DialOptions to be set on the connection
|
// WithDialOpts allows grpc.DialOptions to be set on the connection
|
||||||
func WithDialOpts(opts []grpc.DialOption) ClientOpt {
|
func WithDialOpts(opts []grpc.DialOption) ClientOpt {
|
||||||
return func(c *clientOpts) error {
|
return func(c *clientOpts) error {
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/platforms"
|
|
||||||
"github.com/containerd/containerd/snapshots"
|
"github.com/containerd/containerd/snapshots"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
@ -190,7 +189,7 @@ func WithSnapshotCleanup(ctx context.Context, client *Client, c containers.Conta
|
|||||||
// root filesystem in read-only mode
|
// root filesystem in read-only mode
|
||||||
func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainerOpts {
|
func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
|
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), client.platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/platforms"
|
|
||||||
"github.com/opencontainers/image-spec/identity"
|
"github.com/opencontainers/image-spec/identity"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ func WithRemappedSnapshotView(id string, i Image, uid, gid uint32) NewContainerO
|
|||||||
|
|
||||||
func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool) NewContainerOpts {
|
func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
|
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), client.platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
"github.com/containerd/containerd/platforms"
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
"github.com/opencontainers/image-spec/identity"
|
"github.com/opencontainers/image-spec/identity"
|
||||||
@ -58,7 +57,7 @@ func WithRestoreImage(ctx context.Context, id string, client *Client, checkpoint
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
|
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), client.platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
image.go
2
image.go
@ -110,7 +110,7 @@ func NewImage(client *Client, i images.Image) Image {
|
|||||||
return &image{
|
return &image{
|
||||||
client: client,
|
client: client,
|
||||||
i: i,
|
i: i,
|
||||||
platform: platforms.Default(),
|
platform: client.platform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
|
|||||||
}
|
}
|
||||||
var platformMatcher = platforms.All
|
var platformMatcher = platforms.All
|
||||||
if !iopts.allPlatforms {
|
if !iopts.allPlatforms {
|
||||||
platformMatcher = platforms.Default()
|
platformMatcher = c.platform
|
||||||
}
|
}
|
||||||
|
|
||||||
var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
var handler images.HandlerFunc = func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/containerd/containerd/archive/compression"
|
"github.com/containerd/containerd/archive/compression"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
"github.com/containerd/containerd/platforms"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
cs = image.ContentStore()
|
cs = image.ContentStore()
|
||||||
platform = platforms.Default()
|
platform = c.platform
|
||||||
)
|
)
|
||||||
manifest, err := images.Manifest(ctx, cs, image.Target(), platform)
|
manifest, err := images.Manifest(ctx, cs, image.Target(), platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
pull.go
2
pull.go
@ -44,7 +44,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Ima
|
|||||||
if len(pullCtx.Platforms) > 1 {
|
if len(pullCtx.Platforms) > 1 {
|
||||||
return nil, errors.New("cannot pull multiplatform image locally, try Fetch")
|
return nil, errors.New("cannot pull multiplatform image locally, try Fetch")
|
||||||
} else if len(pullCtx.Platforms) == 0 {
|
} else if len(pullCtx.Platforms) == 0 {
|
||||||
pullCtx.PlatformMatcher = platforms.Default()
|
pullCtx.PlatformMatcher = c.platform
|
||||||
} else {
|
} else {
|
||||||
p, err := platforms.Parse(pullCtx.Platforms[0])
|
p, err := platforms.Parse(pullCtx.Platforms[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user