Share Dialer and DialAddress between client and shim

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-08-10 16:47:02 -07:00
parent 587a811d09
commit 7ac351cdfe
No known key found for this signature in database
GPG Key ID: 40CF16616B361216
4 changed files with 9 additions and 17 deletions

View File

@ -67,7 +67,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
grpc.WithTimeout(60 * time.Second),
grpc.FailOnNonTempDialError(true),
grpc.WithBackoffMaxDelay(3 * time.Second),
grpc.WithDialer(dialer),
grpc.WithDialer(Dialer),
}
if len(copts.dialOptions) > 0 {
gopts = copts.dialOptions
@ -79,7 +79,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
grpc.WithStreamInterceptor(stream),
)
}
conn, err := grpc.Dial(dialAddress(address), gopts...)
conn, err := grpc.Dial(DialAddress(address), gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", address)
}

View File

@ -31,7 +31,7 @@ type dialResult struct {
err error
}
func dialer(address string, timeout time.Duration) (net.Conn, error) {
func Dialer(address string, timeout time.Duration) (net.Conn, error) {
var (
stopC = make(chan struct{})
synC = make(chan *dialResult)
@ -69,6 +69,6 @@ func dialer(address string, timeout time.Duration) (net.Conn, error) {
}
}
func dialAddress(address string) string {
func DialAddress(address string) string {
return fmt.Sprintf("unix://%s", address)
}

View File

@ -7,10 +7,10 @@ import (
winio "github.com/Microsoft/go-winio"
)
func dialer(address string, timeout time.Duration) (net.Conn, error) {
func Dialer(address string, timeout time.Duration) (net.Conn, error) {
return winio.DialPipe(address, &timeout)
}
func dialAddress(address string) string {
func DialAddress(address string) string {
return address
}

View File

@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/containerd/containerd"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
@ -171,7 +172,7 @@ func dumpStacks() {
}
func connectEvents(address string) (eventsapi.EventsClient, error) {
conn, err := connect(address, dialer)
conn, err := connect(address, containerd.Dialer)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", address)
}
@ -187,22 +188,13 @@ func connect(address string, d func(string, time.Duration) (net.Conn, error)) (*
grpc.FailOnNonTempDialError(true),
grpc.WithBackoffMaxDelay(3 * time.Second),
}
conn, err := grpc.Dial(dialAddress(address), gopts...)
conn, err := grpc.Dial(containerd.DialAddress(address), gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", address)
}
return conn, nil
}
func dialer(address string, timeout time.Duration) (net.Conn, error) {
address = strings.TrimPrefix(address, "unix://")
return net.DialTimeout("unix", address, timeout)
}
func dialAddress(address string) string {
return fmt.Sprintf("unix://%s", address)
}
type remoteEventsPublisher struct {
client eventsapi.EventsClient
}