From 7ac351cdfe9181768d2a494cdf62edb164618bf8 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 10 Aug 2017 16:47:02 -0700 Subject: [PATCH] Share Dialer and DialAddress between client and shim Signed-off-by: Kenfe-Mickael Laventure --- client.go | 4 ++-- client_unix.go | 4 ++-- client_windows.go | 4 ++-- cmd/containerd-shim/main_unix.go | 14 +++----------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/client.go b/client.go index 201b18f9c..ebe11efd6 100644 --- a/client.go +++ b/client.go @@ -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) } diff --git a/client_unix.go b/client_unix.go index 565a7d166..e3715571f 100644 --- a/client_unix.go +++ b/client_unix.go @@ -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) } diff --git a/client_windows.go b/client_windows.go index 548024e5b..7f15adbd6 100644 --- a/client_windows.go +++ b/client_windows.go @@ -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 } diff --git a/cmd/containerd-shim/main_unix.go b/cmd/containerd-shim/main_unix.go index 6b5d8010b..eac15d617 100644 --- a/cmd/containerd-shim/main_unix.go +++ b/cmd/containerd-shim/main_unix.go @@ -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 }