in store/engine/etcd/etcd.go [78:130]
func New(id string, cfg *Config) (*Etcd, error) {
if len(id) == 0 {
return nil, errors.New("id must NOT be a empty string")
}
clientConfig := clientv3.Config{
Endpoints: cfg.Addrs,
DialTimeout: defaultDialTimeout,
Logger: logger.Get(),
}
if cfg.TLS.Enable {
tlsInfo := transport.TLSInfo{
CertFile: cfg.TLS.CertFile,
KeyFile: cfg.TLS.KeyFile,
TrustedCAFile: cfg.TLS.TrustedCAFile,
}
tlsConfig, err := tlsInfo.ClientConfig()
if err != nil {
return nil, err
}
clientConfig.TLS = tlsConfig
}
if cfg.Username != "" && cfg.Password != "" {
clientConfig.Username = cfg.Username
clientConfig.Password = cfg.Password
}
client, err := clientv3.New(clientConfig)
if err != nil {
return nil, err
}
electPath := defaultElectPath
if cfg.ElectPath != "" {
electPath = cfg.ElectPath
}
e := &Etcd{
myID: id,
electPath: electPath,
client: client,
kv: clientv3.NewKV(client),
quitCh: make(chan struct{}),
electionCh: make(chan *concurrency.Election),
leaderChangeCh: make(chan bool),
}
e.isReady.Store(false)
e.wg.Add(2)
go e.electLoop(context.Background())
go e.observeLeaderEvent(context.Background())
return e, nil
}