Skip to content

Commit

Permalink
Merge pull request #7499 from heyitsanthony/fix-etcdctl-add-member-env
Browse files Browse the repository at this point in the history
ctlv3: ensure synced member list before printing env vars on member add
  • Loading branch information
Anthony Romano authored Mar 15, 2017
2 parents 2796091 + 3e86779 commit 8f83d11
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions etcdctl/ctlv3/command/member_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {

urls := strings.Split(memberPeerURLs, ",")
ctx, cancel := commandCtx(cmd)
resp, err := mustClientFromCmd(cmd).MemberAdd(ctx, urls)
cli := mustClientFromCmd(cmd)
resp, err := cli.MemberAdd(ctx, urls)
cancel()
if err != nil {
ExitWithError(ExitError, err)
Expand All @@ -118,12 +119,24 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {

if _, ok := (display).(*simplePrinter); ok {
ctx, cancel = commandCtx(cmd)
listResp, err := mustClientFromCmd(cmd).MemberList(ctx)
cancel()

if err != nil {
ExitWithError(ExitError, err)
listResp, err := cli.MemberList(ctx)
// get latest member list; if there's failover new member might have outdated list
for {
if err != nil {
ExitWithError(ExitError, err)
}
if listResp.Header.MemberId == resp.Header.MemberId {
break
}
// quorum get to sync cluster list
gresp, gerr := cli.Get(ctx, "_")
if gerr != nil {
ExitWithError(ExitError, err)
}
resp.Header.MemberId = gresp.Header.MemberId
listResp, err = cli.MemberList(ctx)
}
cancel()

conf := []string{}
for _, memb := range listResp.Members {
Expand Down

0 comments on commit 8f83d11

Please sign in to comment.