X Tutup
Skip to content

Commit 4dd75be

Browse files
committed
Unify dialer implementations
Instead of having several dialer implementations, leave only one in `pkg/dialer` and call it from `pkg/ttrpcutil`, `runtime/v(1|2)/shim` which had their own Closes containerd#3471. Signed-off-by: Kiril Vladimiroff <kiril@vladimiroff.org>
1 parent 640ca78 commit 4dd75be

File tree

6 files changed

+7
-101
lines changed

6 files changed

+7
-101
lines changed

pkg/dialer/dialer_windows.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,13 @@ package dialer
1919
import (
2020
"net"
2121
"os"
22-
"syscall"
2322
"time"
2423

2524
winio "github.com/Microsoft/go-winio"
2625
)
2726

2827
func isNoent(err error) bool {
29-
if err != nil {
30-
if oerr, ok := err.(*os.PathError); ok {
31-
if oerr.Err == syscall.ENOENT {
32-
return true
33-
}
34-
}
35-
}
36-
return false
28+
return os.IsNotExist(err)
3729
}
3830

3931
func dialer(address string, timeout time.Duration) (net.Conn, error) {

pkg/ttrpcutil/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
v1 "github.com/containerd/containerd/api/services/ttrpc/events/v1"
24+
"github.com/containerd/containerd/pkg/dialer"
2425
"github.com/containerd/ttrpc"
2526
"github.com/pkg/errors"
2627
)
@@ -40,7 +41,7 @@ type Client struct {
4041
// NewClient returns a new containerd TTRPC client that is connected to the containerd instance provided by address
4142
func NewClient(address string, opts ...ttrpc.ClientOpts) (*Client, error) {
4243
connector := func() (*ttrpc.Client, error) {
43-
conn, err := ttrpcDial(address, ttrpcDialTimeout)
44+
conn, err := dialer.Dialer(address, ttrpcDialTimeout)
4445
if err != nil {
4546
return nil, errors.Wrap(err, "failed to connect")
4647
}

pkg/ttrpcutil/client_unix.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

pkg/ttrpcutil/client_windows.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

runtime/v1/shim/client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040

4141
"github.com/containerd/containerd/events"
4242
"github.com/containerd/containerd/log"
43+
"github.com/containerd/containerd/pkg/dialer"
4344
v1 "github.com/containerd/containerd/runtime/v1"
4445
"github.com/containerd/containerd/runtime/v1/shim"
4546
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
@@ -228,7 +229,7 @@ func connect(address string, d func(string, time.Duration) (net.Conn, error)) (n
228229

229230
func annonDialer(address string, timeout time.Duration) (net.Conn, error) {
230231
address = strings.TrimPrefix(address, "unix://")
231-
return net.DialTimeout("unix", "\x00"+address, timeout)
232+
return dialer.Dialer("\x00"+address, timeout)
232233
}
233234

234235
// WithConnect connects to an existing shim

runtime/v2/shim/util_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"time"
3131

3232
"github.com/containerd/containerd/namespaces"
33+
"github.com/containerd/containerd/pkg/dialer"
3334
"github.com/containerd/containerd/sys"
3435
"github.com/pkg/errors"
3536
)
@@ -75,7 +76,7 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
7576
// AnonDialer returns a dialer for an abstract socket
7677
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
7778
address = strings.TrimPrefix(address, "unix://")
78-
return net.DialTimeout("unix", "\x00"+address, timeout)
79+
return dialer.Dialer("\x00"+address, timeout)
7980
}
8081

8182
func AnonReconnectDialer(address string, timeout time.Duration) (net.Conn, error) {

0 commit comments

Comments
 (0)
X Tutup