Use containerd client and default namespace

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
docker-18.09
Derek McGowan 2017-06-13 14:51:06 -07:00
parent f15aa3452c
commit f330f4b42b
1 changed files with 9 additions and 30 deletions

View File

@ -10,15 +10,9 @@ import (
"strings" "strings"
"time" "time"
contentapi "github.com/containerd/containerd/api/services/content" "github.com/containerd/containerd"
diffapi "github.com/containerd/containerd/api/services/diff"
snapshotapi "github.com/containerd/containerd/api/services/snapshot"
contentservice "github.com/containerd/containerd/services/content"
diffservice "github.com/containerd/containerd/services/diff"
snapshotservice "github.com/containerd/containerd/services/snapshot"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tonistiigi/buildkit_poc/worker/runcworker" "github.com/tonistiigi/buildkit_poc/worker/runcworker"
"google.golang.org/grpc"
) )
func NewContainerd(root, address string) (*Controller, error) { func NewContainerd(root, address string) (*Controller, error) {
@ -27,23 +21,12 @@ func NewContainerd(root, address string) (*Controller, error) {
} }
// TODO: take lock to make sure there are no duplicates // TODO: take lock to make sure there are no duplicates
client, err := containerd.New(address, containerd.WithDefaultNamespace("buildkit"))
gopts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithInsecure(),
grpc.WithTimeout(100 * time.Second),
grpc.WithDialer(dialer),
grpc.FailOnNonTempDialError(true),
}
conn, err := grpc.Dial(dialAddress(address), gopts...)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to connect to %q . make sure containerd is running", address) return nil, errors.Wrapf(err, "failed to connect client to %q . make sure containerd is running", address)
} }
pd, err := newPullDeps(conn) pd := newPullDeps(client)
if err != nil {
return nil, err
}
opt, err := defaultControllerOpts(root, *pd) opt, err := defaultControllerOpts(root, *pd)
if err != nil { if err != nil {
@ -60,16 +43,12 @@ func NewContainerd(root, address string) (*Controller, error) {
return NewController(*opt) return NewController(*opt)
} }
func newPullDeps(conn *grpc.ClientConn) (*pullDeps, error) { func newPullDeps(client *containerd.Client) *pullDeps {
s := snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotClient(conn))
c := contentservice.NewStoreFromClient(contentapi.NewContentClient(conn))
a := diffservice.NewDiffServiceFromClient(diffapi.NewDiffClient(conn))
return &pullDeps{ return &pullDeps{
Snapshotter: s, Snapshotter: client.SnapshotService(),
ContentStore: c, ContentStore: client.ContentStore(),
Applier: a, Applier: client.DiffService(),
}, nil }
} }
func dialer(address string, timeout time.Duration) (net.Conn, error) { func dialer(address string, timeout time.Duration) (net.Conn, error) {