Merge pull request #1767 from stevvooe/ttrpc-shim

linux/shim: reduce memory overhead by using ttrpc
This commit is contained in:
Phil Estes
2017-11-28 12:43:41 -05:00
committed by GitHub
20 changed files with 1375 additions and 726 deletions

View File

@@ -6,12 +6,9 @@ import (
"fmt"
"io/ioutil"
"net"
"time"
gocontext "context"
"google.golang.org/grpc"
"github.com/containerd/console"
"github.com/containerd/containerd/cmd/ctr/commands"
shim "github.com/containerd/containerd/linux/shim/v1"
@@ -20,6 +17,7 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stevvooe/ttrpc"
"github.com/urfave/cli"
)
@@ -212,21 +210,21 @@ var execCommand = cli.Command{
},
}
func getShimService(context *cli.Context) (shim.ShimClient, error) {
func getShimService(context *cli.Context) (shim.ShimService, error) {
bindSocket := context.GlobalString("socket")
if bindSocket == "" {
return nil, errors.New("socket path must be specified")
}
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(100 * time.Second)}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", "\x00"+bindSocket, timeout)
},
))
conn, err := grpc.Dial(fmt.Sprintf("unix://%s", bindSocket), dialOpts...)
conn, err := net.Dial("unix", "\x00"+bindSocket)
if err != nil {
return nil, err
}
return shim.NewShimClient(conn), nil
client := ttrpc.NewClient(conn)
// TODO(stevvooe): This actually leaks the connection. We were leaking it
// before, so may not be a huge deal.
return shim.NewShimClient(client), nil
}