Move dial funcs to dialer pkg
This reduces shim size from 30mb to 18mb Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
01cdf330bb
commit
526d15bd86
@ -22,6 +22,7 @@ import (
|
|||||||
versionservice "github.com/containerd/containerd/api/services/version/v1"
|
versionservice "github.com/containerd/containerd/api/services/version/v1"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
|
"github.com/containerd/containerd/dialer"
|
||||||
"github.com/containerd/containerd/diff"
|
"github.com/containerd/containerd/diff"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
@ -72,7 +73,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
grpc.WithTimeout(60 * time.Second),
|
grpc.WithTimeout(60 * time.Second),
|
||||||
grpc.FailOnNonTempDialError(true),
|
grpc.FailOnNonTempDialError(true),
|
||||||
grpc.WithBackoffMaxDelay(3 * time.Second),
|
grpc.WithBackoffMaxDelay(3 * time.Second),
|
||||||
grpc.WithDialer(Dialer),
|
grpc.WithDialer(dialer.Dialer),
|
||||||
}
|
}
|
||||||
if len(copts.dialOptions) > 0 {
|
if len(copts.dialOptions) > 0 {
|
||||||
gopts = copts.dialOptions
|
gopts = copts.dialOptions
|
||||||
@ -84,7 +85,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
|
|||||||
grpc.WithStreamInterceptor(stream),
|
grpc.WithStreamInterceptor(stream),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
conn, err := grpc.Dial(DialAddress(address), gopts...)
|
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
|
||||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||||
|
"github.com/containerd/containerd/dialer"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/events"
|
"github.com/containerd/containerd/events"
|
||||||
"github.com/containerd/containerd/linux/shim"
|
"github.com/containerd/containerd/linux/shim"
|
||||||
@ -212,7 +212,7 @@ func dumpStacks(logger *logrus.Entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func connectEvents(address string) (eventsapi.EventsClient, error) {
|
func connectEvents(address string) (eventsapi.EventsClient, error) {
|
||||||
conn, err := connect(address, containerd.Dialer)
|
conn, err := connect(address, dialer.Dialer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ func connect(address string, d func(string, time.Duration) (net.Conn, error)) (*
|
|||||||
grpc.FailOnNonTempDialError(true),
|
grpc.FailOnNonTempDialError(true),
|
||||||
grpc.WithBackoffMaxDelay(3 * time.Second),
|
grpc.WithBackoffMaxDelay(3 * time.Second),
|
||||||
}
|
}
|
||||||
conn, err := grpc.Dial(containerd.DialAddress(address), gopts...)
|
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package containerd
|
package dialer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -12,6 +13,12 @@ type dialResult struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DialAddress returns the address with unix:// prepended to the
|
||||||
|
// provided address
|
||||||
|
func DialAddress(address string) string {
|
||||||
|
return fmt.Sprintf("unix://%s", address)
|
||||||
|
}
|
||||||
|
|
||||||
// Dialer returns a GRPC net.Conn connected to the provided address
|
// Dialer returns a GRPC net.Conn connected to the provided address
|
||||||
func Dialer(address string, timeout time.Duration) (net.Conn, error) {
|
func Dialer(address string, timeout time.Duration) (net.Conn, error) {
|
||||||
var (
|
var (
|
@ -1,9 +1,8 @@
|
|||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package containerd
|
package dialer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -28,9 +27,3 @@ func dialer(address string, timeout time.Duration) (net.Conn, error) {
|
|||||||
address = strings.TrimPrefix(address, "unix://")
|
address = strings.TrimPrefix(address, "unix://")
|
||||||
return net.DialTimeout("unix", address, timeout)
|
return net.DialTimeout("unix", address, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialAddress returns the address with unix:// prepended to the
|
|
||||||
// provided address
|
|
||||||
func DialAddress(address string) string {
|
|
||||||
return fmt.Sprintf("unix://%s", address)
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package containerd
|
package dialer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
Loading…
Reference in New Issue
Block a user