Move shim client into subpackage
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
13c7c3ef10
commit
bba473aeb1
@ -11,7 +11,8 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/events/exchange"
|
"github.com/containerd/containerd/events/exchange"
|
||||||
"github.com/containerd/containerd/linux/runcopts"
|
"github.com/containerd/containerd/linux/runcopts"
|
||||||
client "github.com/containerd/containerd/linux/shim"
|
"github.com/containerd/containerd/linux/shim"
|
||||||
|
"github.com/containerd/containerd/linux/shim/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -71,26 +72,26 @@ type bundle struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ShimOpt specifies shim options for initialization and connection
|
// ShimOpt specifies shim options for initialization and connection
|
||||||
type ShimOpt func(*bundle, string, *runcopts.RuncOptions) (client.Config, client.ClientOpt)
|
type ShimOpt func(*bundle, string, *runcopts.RuncOptions) (shim.Config, client.ClientOpt)
|
||||||
|
|
||||||
// ShimRemote is a ShimOpt for connecting and starting a remote shim
|
// ShimRemote is a ShimOpt for connecting and starting a remote shim
|
||||||
func ShimRemote(shim, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) ShimOpt {
|
func ShimRemote(shimBinary, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) ShimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts),
|
return b.shimConfig(ns, ropts),
|
||||||
client.WithStart(shim, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
|
client.WithStart(shimBinary, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShimLocal is a ShimOpt for using an in process shim implementation
|
// ShimLocal is a ShimOpt for using an in process shim implementation
|
||||||
func ShimLocal(exchange *exchange.Exchange) ShimOpt {
|
func ShimLocal(exchange *exchange.Exchange) ShimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
|
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShimConnect is a ShimOpt for connecting to an existing remote shim
|
// ShimConnect is a ShimOpt for connecting to an existing remote shim
|
||||||
func ShimConnect() ShimOpt {
|
func ShimConnect() ShimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (client.Config, client.ClientOpt) {
|
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.ClientOpt) {
|
||||||
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +120,7 @@ func (b *bundle) shimAddress(namespace string) string {
|
|||||||
return filepath.Join(string(filepath.Separator), "containerd-shim", namespace, b.id, "shim.sock")
|
return filepath.Join(string(filepath.Separator), "containerd-shim", namespace, b.id, "shim.sock")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bundle) shimConfig(namespace string, runcOptions *runcopts.RuncOptions) client.Config {
|
func (b *bundle) shimConfig(namespace string, runcOptions *runcopts.RuncOptions) shim.Config {
|
||||||
var (
|
var (
|
||||||
criuPath string
|
criuPath string
|
||||||
runtimeRoot string
|
runtimeRoot string
|
||||||
@ -130,7 +131,7 @@ func (b *bundle) shimConfig(namespace string, runcOptions *runcopts.RuncOptions)
|
|||||||
systemdCgroup = runcOptions.SystemdCgroup
|
systemdCgroup = runcOptions.SystemdCgroup
|
||||||
runtimeRoot = runcOptions.RuntimeRoot
|
runtimeRoot = runcOptions.RuntimeRoot
|
||||||
}
|
}
|
||||||
return client.Config{
|
return shim.Config{
|
||||||
Path: b.path,
|
Path: b.path,
|
||||||
WorkDir: b.workDir,
|
WorkDir: b.workDir,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package shim
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -20,19 +20,23 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/containerd/containerd/events"
|
"github.com/containerd/containerd/events"
|
||||||
shim "github.com/containerd/containerd/linux/shim/v1"
|
"github.com/containerd/containerd/linux/shim"
|
||||||
|
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/reaper"
|
"github.com/containerd/containerd/reaper"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
|
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var empty = &google_protobuf.Empty{}
|
||||||
|
|
||||||
// ClientOpt is an option for a shim client configuration
|
// ClientOpt is an option for a shim client configuration
|
||||||
type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error)
|
type ClientOpt func(context.Context, shim.Config) (shimapi.ShimClient, io.Closer, error)
|
||||||
|
|
||||||
// WithStart executes a new shim process
|
// WithStart executes a new shim process
|
||||||
func WithStart(binary, address, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) ClientOpt {
|
func WithStart(binary, address, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) ClientOpt {
|
||||||
return func(ctx context.Context, config Config) (_ shim.ShimClient, _ io.Closer, err error) {
|
return func(ctx context.Context, config shim.Config) (_ shimapi.ShimClient, _ io.Closer, err error) {
|
||||||
socket, err := newSocket(address)
|
socket, err := newSocket(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -84,7 +88,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, nonewns, debug boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCommand(binary, daemonAddress string, nonewns, debug bool, config Config, socket *os.File) *exec.Cmd {
|
func newCommand(binary, daemonAddress string, nonewns, debug bool, config shim.Config, socket *os.File) *exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"-namespace", config.Namespace,
|
"-namespace", config.Namespace,
|
||||||
"-workdir", config.WorkDir,
|
"-workdir", config.WorkDir,
|
||||||
@ -161,38 +165,28 @@ func dialAddress(address string) string {
|
|||||||
|
|
||||||
// WithConnect connects to an existing shim
|
// WithConnect connects to an existing shim
|
||||||
func WithConnect(address string) ClientOpt {
|
func WithConnect(address string) ClientOpt {
|
||||||
return func(ctx context.Context, config Config) (shim.ShimClient, io.Closer, error) {
|
return func(ctx context.Context, config shim.Config) (shimapi.ShimClient, io.Closer, error) {
|
||||||
conn, err := connect(address, annonDialer)
|
conn, err := connect(address, annonDialer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return shim.NewShimClient(conn), conn, nil
|
return shimapi.NewShimClient(conn), conn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLocal uses an in process shim
|
// WithLocal uses an in process shim
|
||||||
func WithLocal(publisher events.Publisher) func(context.Context, Config) (shim.ShimClient, io.Closer, error) {
|
func WithLocal(publisher events.Publisher) func(context.Context, shim.Config) (shimapi.ShimClient, io.Closer, error) {
|
||||||
return func(ctx context.Context, config Config) (shim.ShimClient, io.Closer, error) {
|
return func(ctx context.Context, config shim.Config) (shimapi.ShimClient, io.Closer, error) {
|
||||||
service, err := NewService(config, publisher)
|
service, err := shim.NewService(config, publisher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return NewLocal(service), nil, nil
|
return shim.NewLocal(service), nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config contains shim specific configuration
|
|
||||||
type Config struct {
|
|
||||||
Path string
|
|
||||||
Namespace string
|
|
||||||
WorkDir string
|
|
||||||
Criu string
|
|
||||||
RuntimeRoot string
|
|
||||||
SystemdCgroup bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns a new shim client
|
// New returns a new shim client
|
||||||
func New(ctx context.Context, config Config, opt ClientOpt) (*Client, error) {
|
func New(ctx context.Context, config shim.Config, opt ClientOpt) (*Client, error) {
|
||||||
s, c, err := opt(ctx, config)
|
s, c, err := opt(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -206,7 +200,7 @@ func New(ctx context.Context, config Config, opt ClientOpt) (*Client, error) {
|
|||||||
|
|
||||||
// Client is a shim client containing the connection to a shim
|
// Client is a shim client containing the connection to a shim
|
||||||
type Client struct {
|
type Client struct {
|
||||||
shim.ShimClient
|
shimapi.ShimClient
|
||||||
|
|
||||||
c io.Closer
|
c io.Closer
|
||||||
exitCh chan struct{}
|
exitCh chan struct{}
|
@ -1,6 +1,6 @@
|
|||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package shim
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
@ -1,6 +1,6 @@
|
|||||||
// +build !linux,!windows
|
// +build !linux,!windows
|
||||||
|
|
||||||
package shim
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
@ -32,6 +32,16 @@ var empty = &google_protobuf.Empty{}
|
|||||||
// RuncRoot is the path to the root runc state directory
|
// RuncRoot is the path to the root runc state directory
|
||||||
const RuncRoot = "/run/containerd/runc"
|
const RuncRoot = "/run/containerd/runc"
|
||||||
|
|
||||||
|
// Config contains shim specific configuration
|
||||||
|
type Config struct {
|
||||||
|
Path string
|
||||||
|
Namespace string
|
||||||
|
WorkDir string
|
||||||
|
Criu string
|
||||||
|
RuntimeRoot string
|
||||||
|
SystemdCgroup bool
|
||||||
|
}
|
||||||
|
|
||||||
// NewService returns a new shim service that can be used via GRPC
|
// NewService returns a new shim service that can be used via GRPC
|
||||||
func NewService(config Config, publisher events.Publisher) (*Service, error) {
|
func NewService(config Config, publisher events.Publisher) (*Service, error) {
|
||||||
if config.Namespace == "" {
|
if config.Namespace == "" {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/containerd/cgroups"
|
"github.com/containerd/cgroups"
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
client "github.com/containerd/containerd/linux/shim"
|
"github.com/containerd/containerd/linux/shim/client"
|
||||||
shim "github.com/containerd/containerd/linux/shim/v1"
|
shim "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
"github.com/gogo/protobuf/types"
|
"github.com/gogo/protobuf/types"
|
||||||
|
Loading…
Reference in New Issue
Block a user