Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix containerd connection wait. #1919

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions container/containerd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package containerd

import (
"context"
"fmt"
"net"
"sync"
"time"

Expand Down Expand Up @@ -49,24 +51,37 @@ type containerdClient interface {
var once sync.Once
var ctrdClient containerdClient = nil

const (
address = "/run/containerd/containerd.sock"
maxBackoffDelay = 3 * time.Second
connectionTimeout = 2 * time.Second
)

// Client creates a containerd client
func Client() (containerdClient, error) {
var retErr error
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{
grpc.WithInsecure(),
grpc.WithDialer(dialer.Dialer),
grpc.WithBlock(),
grpc.WithTimeout(2 * time.Second),
grpc.WithBackoffMaxDelay(3 * time.Second),
grpc.WithBackoffMaxDelay(maxBackoffDelay),
grpc.WithTimeout(connectionTimeout),
}
unary, stream := newNSInterceptors(k8sNamespace)
gopts = append(gopts,
grpc.WithUnaryInterceptor(unary),
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 {
retErr = err
return
Expand Down