Fix containerd connection wait.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
834edaddc4
commit
021065e3b9
@ -16,6 +16,8 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -49,16 +51,29 @@ type containerdClient interface {
|
|||||||
var once sync.Once
|
var once sync.Once
|
||||||
var ctrdClient containerdClient = nil
|
var ctrdClient containerdClient = nil
|
||||||
|
|
||||||
|
const (
|
||||||
|
address = "/run/containerd/containerd.sock"
|
||||||
|
maxBackoffDelay = 3 * time.Second
|
||||||
|
connectionTimeout = 2 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// Client creates a containerd client
|
// Client creates a containerd client
|
||||||
func Client() (containerdClient, error) {
|
func Client() (containerdClient, error) {
|
||||||
var retErr error
|
var retErr error
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
|
tryConn, err := net.DialTimeout("unix", address, connectionTimeout)
|
||||||
|
if err != nil {
|
||||||
|
retErr = fmt.Errorf("containerd: cannot unix dial containerd api service: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tryConn.Close()
|
||||||
|
|
||||||
gopts := []grpc.DialOption{
|
gopts := []grpc.DialOption{
|
||||||
grpc.WithInsecure(),
|
grpc.WithInsecure(),
|
||||||
grpc.WithDialer(dialer.Dialer),
|
grpc.WithDialer(dialer.Dialer),
|
||||||
grpc.WithBlock(),
|
grpc.WithBlock(),
|
||||||
grpc.WithTimeout(2 * time.Second),
|
grpc.WithBackoffMaxDelay(maxBackoffDelay),
|
||||||
grpc.WithBackoffMaxDelay(3 * time.Second),
|
grpc.WithTimeout(connectionTimeout),
|
||||||
}
|
}
|
||||||
unary, stream := newNSInterceptors(k8sNamespace)
|
unary, stream := newNSInterceptors(k8sNamespace)
|
||||||
gopts = append(gopts,
|
gopts = append(gopts,
|
||||||
@ -66,7 +81,7 @@ func Client() (containerdClient, error) {
|
|||||||
grpc.WithStreamInterceptor(stream),
|
grpc.WithStreamInterceptor(stream),
|
||||||
)
|
)
|
||||||
|
|
||||||
conn, err := grpc.Dial(dialer.DialAddress("/var/run/containerd/containerd.sock"), gopts...)
|
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retErr = err
|
retErr = err
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user