Merge pull request #8683 from gyuho/ctl

etcdctl/ctlv3: inherit/update flags only once in 'check' command
release-3.3
Gyu-Ho Lee 2017-10-11 10:51:40 -07:00 committed by GitHub
commit 764a0f79b2
3 changed files with 40 additions and 17 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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)