Merge pull request #2513 from iwankgb/deprecated_grpc.WithDialer

Getting rid of depracated grpc function calls
This commit is contained in:
David Ashpole 2020-05-13 09:07:41 -07:00 committed by GitHub
commit 6a8d61401e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -34,10 +34,6 @@ issues:
# Stuttering affects exported names:
- "type name will be used as .*\\.[A-Z]{1}.* by other packages, and that stutters"
exclude-rules:
# container/containerd/client.go:67:4: SA1019: grpc.WithDialer is deprecated: use WithContextDialer instead. Will be supported throughout 1.x. (staticcheck)
# There are more similar issues in following lines.
- path: container/containerd/client.go
text: "SA1019:"
# utils/cpuload/netlink/netlink.go:102:15: Error return value of `binary.Write` is not checked (errcheck)
# There are more similar issues in this file
- path: utils/cpuload/netlink/netlink.go

View File

@ -29,6 +29,7 @@ import (
"github.com/containerd/containerd/pkg/dialer"
ptypes "github.com/gogo/protobuf/types"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
)
type client struct {
@ -48,6 +49,7 @@ var ctrdClient ContainerdClient = nil
const (
maxBackoffDelay = 3 * time.Second
baseBackoffDelay = 100 * time.Millisecond
connectionTimeout = 2 * time.Second
)
@ -62,12 +64,17 @@ func Client(address, namespace string) (ContainerdClient, error) {
}
tryConn.Close()
connParams := grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: baseBackoffDelay,
MaxDelay: maxBackoffDelay,
},
}
gopts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithDialer(dialer.Dialer),
grpc.WithContextDialer(dialer.ContextDialer),
grpc.WithBlock(),
grpc.WithBackoffMaxDelay(maxBackoffDelay),
grpc.WithTimeout(connectionTimeout),
grpc.WithConnectParams(connParams),
}
unary, stream := newNSInterceptors(namespace)
gopts = append(gopts,
@ -75,7 +82,9 @@ func Client(address, namespace string) (ContainerdClient, error) {
grpc.WithStreamInterceptor(stream),
)
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
defer cancel()
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
if err != nil {
retErr = err
return