Skip to content

Commit

Permalink
Merge pull request #8683 from gyuho/ctl
Browse files Browse the repository at this point in the history
etcdctl/ctlv3: inherit/update flags only once in 'check' command
  • Loading branch information
gyuho committed Oct 11, 2017
2 parents 0ef0abf + e80b247 commit 764a0f7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
5 changes: 3 additions & 2 deletions etcdctl/ctlv3/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 27 additions & 13 deletions etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 cfg
}

return mustClient(endpoints, dialTimeout, keepAliveTime, keepAliveTimeout, sec, auth)
func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
cfg := clientConfigFromCmd(cmd)
return cfg.mustClient()
}

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 (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)
}
Expand Down
10 changes: 9 additions & 1 deletion etcdctl/ctlv3/command/make_mirror_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 764a0f7

Please sign in to comment.