mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
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:
parent
06dc8cf4cb
commit
3ad4fedede
@ -18,6 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -25,10 +26,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
clientv2 "github.com/coreos/etcd/client"
|
clientv2 "github.com/coreos/etcd/client"
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
|
"google.golang.org/grpc"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -113,7 +113,13 @@ func (e *CombinedEtcdClient) clientV2() (clientv2.KeysAPI, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *CombinedEtcdClient) clientV3() (*clientv3.Client, 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.
|
// Backup creates a backup of an etcd2 data directory at the given backupDir.
|
||||||
|
Loading…
Reference in New Issue
Block a user