cluster/.../etcd/migrate: block etcd client creation until connection is up

The new etcd balancer (>3.3.14, 3.4.0) uses an asynchronous resolver for
endpoints. Without "WithBlock", the client may return before the
connection is up.

Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
This commit is contained in:
Gyuho Lee 2019-08-14 17:26:39 -07:00
parent 06dc8cf4cb
commit 3ad4fedede

View File

@ -18,6 +18,7 @@ package main
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
@ -25,10 +26,9 @@ import (
"strings"
"time"
"context"
clientv2 "github.com/coreos/etcd/client"
"github.com/coreos/etcd/clientv3"
"google.golang.org/grpc"
"k8s.io/klog"
)
@ -113,7 +113,13 @@ func (e *CombinedEtcdClient) clientV2() (clientv2.KeysAPI, error) {
}
func (e *CombinedEtcdClient) clientV3() (*clientv3.Client, error) {
return clientv3.New(clientv3.Config{Endpoints: []string{e.endpoint()}})
return clientv3.New(clientv3.Config{
Endpoints: []string{e.endpoint()},
DialTimeout: 20 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithBlock(), // block until the underlying connection is up
},
})
}
// Backup creates a backup of an etcd2 data directory at the given backupDir.