mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl/ctlv3: inherit/update flags only once in 'check' command
When creating multiple clients, 'mustClientFromCmd' overwrites inherited flags with environment variables, so later clients were printing warnings on duplicate key updates. Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
0ef0abf9bf
commit
e80b2474fa
@ -112,9 +112,10 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
|
||||
requests := make(chan v3.Op, cfg.clients)
|
||||
limit := rate.NewLimiter(rate.Limit(cfg.limit), 1)
|
||||
|
||||
var clients []*v3.Client
|
||||
cc := clientConfigFromCmd(cmd)
|
||||
clients := make([]*v3.Client, cfg.clients)
|
||||
for i := 0; i < cfg.clients; i++ {
|
||||
clients = append(clients, mustClientFromCmd(cmd))
|
||||
clients[i] = cc.mustClient()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.duration)*time.Second)
|
||||
|
@ -92,13 +92,22 @@ func initDisplayFromCmd(cmd *cobra.Command) {
|
||||
}
|
||||
}
|
||||
|
||||
func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
|
||||
type clientConfig struct {
|
||||
endpoints []string
|
||||
dialTimeout time.Duration
|
||||
keepAliveTime time.Duration
|
||||
keepAliveTimeout time.Duration
|
||||
scfg *secureCfg
|
||||
acfg *authCfg
|
||||
}
|
||||
|
||||
func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
|
||||
fs := cmd.InheritedFlags()
|
||||
flags.SetPflagsFromEnv("ETCDCTL", fs)
|
||||
|
||||
debug, derr := cmd.Flags().GetBool("debug")
|
||||
if derr != nil {
|
||||
ExitWithError(ExitError, derr)
|
||||
debug, err := cmd.Flags().GetBool("debug")
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
if debug {
|
||||
clientv3.SetLogger(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4))
|
||||
@ -107,25 +116,30 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
|
||||
})
|
||||
}
|
||||
|
||||
endpoints, err := endpointsFromCmd(cmd)
|
||||
cfg := &clientConfig{}
|
||||
cfg.endpoints, err = endpointsFromCmd(cmd)
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
|
||||
dialTimeout := dialTimeoutFromCmd(cmd)
|
||||
keepAliveTime := keepAliveTimeFromCmd(cmd)
|
||||
keepAliveTimeout := keepAliveTimeoutFromCmd(cmd)
|
||||
cfg.dialTimeout = dialTimeoutFromCmd(cmd)
|
||||
cfg.keepAliveTime = keepAliveTimeFromCmd(cmd)
|
||||
cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd)
|
||||
|
||||
sec := secureCfgFromCmd(cmd)
|
||||
auth := authCfgFromCmd(cmd)
|
||||
cfg.scfg = secureCfgFromCmd(cmd)
|
||||
cfg.acfg = authCfgFromCmd(cmd)
|
||||
|
||||
initDisplayFromCmd(cmd)
|
||||
|
||||
return mustClient(endpoints, dialTimeout, keepAliveTime, keepAliveTimeout, sec, auth)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func mustClient(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) *clientv3.Client {
|
||||
cfg, err := newClientCfg(endpoints, dialTimeout, keepAliveTime, keepAliveTimeout, scfg, acfg)
|
||||
func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
|
||||
cfg := clientConfigFromCmd(cmd)
|
||||
return cfg.mustClient()
|
||||
}
|
||||
|
||||
func (cc *clientConfig) mustClient() *clientv3.Client {
|
||||
cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg)
|
||||
if err != nil {
|
||||
ExitWithError(ExitBadArgs, err)
|
||||
}
|
||||
|
@ -75,7 +75,15 @@ func makeMirrorCommandFunc(cmd *cobra.Command, args []string) {
|
||||
insecureTransport: mminsecureTr,
|
||||
}
|
||||
|
||||
dc := mustClient([]string{args[0]}, dialTimeout, keepAliveTime, keepAliveTimeout, sec, nil)
|
||||
cc := &clientConfig{
|
||||
endpoints: []string{args[0]},
|
||||
dialTimeout: dialTimeout,
|
||||
keepAliveTime: keepAliveTime,
|
||||
keepAliveTimeout: keepAliveTimeout,
|
||||
scfg: sec,
|
||||
acfg: nil,
|
||||
}
|
||||
dc := cc.mustClient()
|
||||
c := mustClientFromCmd(cmd)
|
||||
|
||||
err := makeMirror(context.TODO(), c, dc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user