Merge pull request #8683 from gyuho/ctl
etcdctl/ctlv3: inherit/update flags only once in 'check' commandrelease-3.3
commit
764a0f79b2
|
@ -112,9 +112,10 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
|
||||||
requests := make(chan v3.Op, cfg.clients)
|
requests := make(chan v3.Op, cfg.clients)
|
||||||
limit := rate.NewLimiter(rate.Limit(cfg.limit), 1)
|
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++ {
|
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)
|
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()
|
fs := cmd.InheritedFlags()
|
||||||
flags.SetPflagsFromEnv("ETCDCTL", fs)
|
flags.SetPflagsFromEnv("ETCDCTL", fs)
|
||||||
|
|
||||||
debug, derr := cmd.Flags().GetBool("debug")
|
debug, err := cmd.Flags().GetBool("debug")
|
||||||
if derr != nil {
|
if err != nil {
|
||||||
ExitWithError(ExitError, derr)
|
ExitWithError(ExitError, err)
|
||||||
}
|
}
|
||||||
if debug {
|
if debug {
|
||||||
clientv3.SetLogger(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4))
|
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 {
|
if err != nil {
|
||||||
ExitWithError(ExitError, err)
|
ExitWithError(ExitError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dialTimeout := dialTimeoutFromCmd(cmd)
|
cfg.dialTimeout = dialTimeoutFromCmd(cmd)
|
||||||
keepAliveTime := keepAliveTimeFromCmd(cmd)
|
cfg.keepAliveTime = keepAliveTimeFromCmd(cmd)
|
||||||
keepAliveTimeout := keepAliveTimeoutFromCmd(cmd)
|
cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd)
|
||||||
|
|
||||||
sec := secureCfgFromCmd(cmd)
|
cfg.scfg = secureCfgFromCmd(cmd)
|
||||||
auth := authCfgFromCmd(cmd)
|
cfg.acfg = authCfgFromCmd(cmd)
|
||||||
|
|
||||||
initDisplayFromCmd(cmd)
|
initDisplayFromCmd(cmd)
|
||||||
|
return cfg
|
||||||
return mustClient(endpoints, dialTimeout, keepAliveTime, keepAliveTimeout, sec, auth)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustClient(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) *clientv3.Client {
|
func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
|
||||||
cfg, err := newClientCfg(endpoints, dialTimeout, keepAliveTime, keepAliveTimeout, scfg, acfg)
|
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 {
|
if err != nil {
|
||||||
ExitWithError(ExitBadArgs, err)
|
ExitWithError(ExitBadArgs, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,15 @@ func makeMirrorCommandFunc(cmd *cobra.Command, args []string) {
|
||||||
insecureTransport: mminsecureTr,
|
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)
|
c := mustClientFromCmd(cmd)
|
||||||
|
|
||||||
err := makeMirror(context.TODO(), c, dc)
|
err := makeMirror(context.TODO(), c, dc)
|
||||||
|
|
Loading…
Reference in New Issue