From e2cb9cbaecf26b62839d4a1f5561bf4bf5ac698c Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 5 Jun 2018 13:36:04 -0700 Subject: [PATCH] ctlv3: support TLS endpoints for move-leader command Signed-off-by: Gyuho Lee --- etcdctl/ctlv3/command/global.go | 11 ++++++----- etcdctl/ctlv3/command/move_leader_command.go | 17 ++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index e52442ff8..6b2f05e3e 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -109,11 +109,12 @@ func (*discardValue) Type() string { return "" } func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { fs := cmd.InheritedFlags() - - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_KEY=foo" warnings - // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_RANGE_END=bar" warnings - fs.AddFlag(&pflag.Flag{Name: "watch-key", Value: &discardValue{}}) - fs.AddFlag(&pflag.Flag{Name: "watch-range-end", Value: &discardValue{}}) + if strings.HasPrefix(cmd.Use, "watch") { + // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_KEY=foo" warnings + // silence "pkg/flags: unrecognized environment variable ETCDCTL_WATCH_RANGE_END=bar" warnings + fs.AddFlag(&pflag.Flag{Name: "watch-key", Value: &discardValue{}}) + fs.AddFlag(&pflag.Flag{Name: "watch-range-end", Value: &discardValue{}}) + } flags.SetPflagsFromEnv("ETCDCTL", fs) debug, err := cmd.Flags().GetBool("debug") diff --git a/etcdctl/ctlv3/command/move_leader_command.go b/etcdctl/ctlv3/command/move_leader_command.go index 3bd44255e..5fdecf95a 100644 --- a/etcdctl/ctlv3/command/move_leader_command.go +++ b/etcdctl/ctlv3/command/move_leader_command.go @@ -17,7 +17,6 @@ package command import ( "fmt" "strconv" - "time" "github.com/coreos/etcd/clientv3" "github.com/spf13/cobra" @@ -53,16 +52,12 @@ func transferLeadershipCommandFunc(cmd *cobra.Command, args []string) { var leaderCli *clientv3.Client var leaderID uint64 for _, ep := range eps { - cli, err := clientv3.New(clientv3.Config{ - Endpoints: []string{ep}, - DialTimeout: 3 * time.Second, - }) - if err != nil { - ExitWithError(ExitError, err) - } - resp, err := cli.Status(ctx, ep) - if err != nil { - ExitWithError(ExitError, err) + cfg := clientConfigFromCmd(cmd) + cfg.endpoints = []string{ep} + cli := cfg.mustClient() + resp, serr := cli.Status(ctx, ep) + if serr != nil { + ExitWithError(ExitError, serr) } if resp.Header.GetMemberId() == resp.Leader {