mirror of
https://github.com/rancher/rke.git
synced 2025-08-30 13:02:45 +00:00
add timeout to etcd member add call
This commit is contained in:
parent
8d11342949
commit
f492ab2894
@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/rancher/rke/util"
|
"github.com/rancher/rke/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
etcdclientv2 "go.etcd.io/etcd/client/v2"
|
etcdclientv2 "go.etcd.io/etcd/client/v2"
|
||||||
|
etcdclientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ const (
|
|||||||
EtcdDataDir = "/var/lib/rancher/etcd/"
|
EtcdDataDir = "/var/lib/rancher/etcd/"
|
||||||
EtcdInitWaitTime = 10
|
EtcdInitWaitTime = 10
|
||||||
EtcdSnapshotWaitTime = 5
|
EtcdSnapshotWaitTime = 5
|
||||||
|
EtcdRequestWaitTimeout = 10
|
||||||
EtcdPermFixContainerName = "etcd-fix-perm"
|
EtcdPermFixContainerName = "etcd-fix-perm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -169,6 +171,14 @@ func RemoveEtcdPlane(ctx context.Context, etcdHosts []*hosts.Host, force bool) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func memberAdd(ctx context.Context, etcdClient *etcdclientv3.Client, peerURL string) error {
|
||||||
|
ctxTimeout, cancel := context.WithTimeout(ctx, EtcdRequestWaitTimeout*time.Second)
|
||||||
|
_, err := etcdClient.MemberAdd(ctxTimeout, []string{peerURL})
|
||||||
|
cancel()
|
||||||
|
_ = etcdClient.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func AddEtcdMember(ctx context.Context, toAddEtcdHost *hosts.Host, etcdHosts []*hosts.Host, localConnDialerFactory hosts.DialerFactory,
|
func AddEtcdMember(ctx context.Context, toAddEtcdHost *hosts.Host, etcdHosts []*hosts.Host, localConnDialerFactory hosts.DialerFactory,
|
||||||
k8sVersion string, cert, key []byte) error {
|
k8sVersion string, cert, key []byte) error {
|
||||||
log.Infof(ctx, "[add/%s] Adding member [etcd-%s] to etcd cluster", ETCDRole, toAddEtcdHost.HostnameOverride)
|
log.Infof(ctx, "[add/%s] Adding member [etcd-%s] to etcd cluster", ETCDRole, toAddEtcdHost.HostnameOverride)
|
||||||
@ -184,7 +194,7 @@ func AddEtcdMember(ctx context.Context, toAddEtcdHost *hosts.Host, etcdHosts []*
|
|||||||
logrus.Debugf("Failed to create etcd client for host [%s]: %v", host.Address, err)
|
logrus.Debugf("Failed to create etcd client for host [%s]: %v", host.Address, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := etcdClient.MemberAdd(ctx, []string{peerURL}); err != nil {
|
if err := memberAdd(ctx, etcdClient, peerURL); err != nil {
|
||||||
logrus.Debugf("Failed to Add etcd member [%s] from host: %v", host.Address, err)
|
logrus.Debugf("Failed to Add etcd member [%s] from host: %v", host.Address, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -228,6 +238,7 @@ func removeEtcdMemberV3(ctx context.Context, toDeleteEtcdHost *hosts.Host, host
|
|||||||
logrus.Debugf("Failed to create etcd client for host [%s]: %v", host.Address, err)
|
logrus.Debugf("Failed to create etcd client for host [%s]: %v", host.Address, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
defer etcdClient.Close()
|
||||||
members, err := etcdClient.MemberList(ctx)
|
members, err := etcdClient.MemberList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Failed to list etcd members from host [%s]: %v", host.Address, err)
|
logrus.Debugf("Failed to list etcd members from host [%s]: %v", host.Address, err)
|
||||||
|
@ -56,6 +56,7 @@ func getEtcdClientV3(ctx context.Context, etcdHost *hosts.Host, localConnDialerF
|
|||||||
Endpoints: []string{"https://" + etcdHost.InternalAddress + ":2379"},
|
Endpoints: []string{"https://" + etcdHost.InternalAddress + ":2379"},
|
||||||
TLS: tlsConfig,
|
TLS: tlsConfig,
|
||||||
DialOptions: []grpc.DialOption{grpc.WithContextDialer(wrapper(dialer))},
|
DialOptions: []grpc.DialOption{grpc.WithContextDialer(wrapper(dialer))},
|
||||||
|
DialTimeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
return etcdclientv3.New(cfg)
|
return etcdclientv3.New(cfg)
|
||||||
|
Loading…
Reference in New Issue
Block a user