From e7146d2c48f015c1def8fc75941e494ca491b1fc Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Wed, 20 Mar 2019 17:02:00 -0700 Subject: [PATCH] etcdctl: add learner field in member list output --- etcdctl/ctlv3/command/member_command.go | 2 +- etcdctl/ctlv3/command/printer.go | 7 ++++++- etcdctl/ctlv3/command/printer_fields.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/etcdctl/ctlv3/command/member_command.go b/etcdctl/ctlv3/command/member_command.go index cbe2be4ff3f..3aefe9da9d6 100644 --- a/etcdctl/ctlv3/command/member_command.go +++ b/etcdctl/ctlv3/command/member_command.go @@ -90,7 +90,7 @@ func NewMemberListCommand() *cobra.Command { Use: "list", Short: "Lists all members in the cluster", Long: `When --write-out is set to simple, this command prints out comma-separated member lists for each endpoint. -The items in the lists are ID, Status, Name, Peer Addrs, Client Addrs. +The items in the lists are ID, Status, Name, Peer Addrs, Client Addrs, Is Learner. `, Run: memberListCommandFunc, diff --git a/etcdctl/ctlv3/command/printer.go b/etcdctl/ctlv3/command/printer.go index cd87811e420..237779c7866 100644 --- a/etcdctl/ctlv3/command/printer.go +++ b/etcdctl/ctlv3/command/printer.go @@ -158,18 +158,23 @@ func (p *printerUnsupported) DBStatus(snapshot.Status) { p.p(nil) } func (p *printerUnsupported) MoveLeader(leader, target uint64, r v3.MoveLeaderResponse) { p.p(nil) } func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string) { - hdr = []string{"ID", "Status", "Name", "Peer Addrs", "Client Addrs"} + hdr = []string{"ID", "Status", "Name", "Peer Addrs", "Client Addrs", "Is Learner"} for _, m := range r.Members { status := "started" if len(m.Name) == 0 { status = "unstarted" } + isLearner := "false" + if m.IsLearner { + isLearner = "true" + } rows = append(rows, []string{ fmt.Sprintf("%x", m.ID), status, m.Name, strings.Join(m.PeerURLs, ","), strings.Join(m.ClientURLs, ","), + isLearner, }) } return hdr, rows diff --git a/etcdctl/ctlv3/command/printer_fields.go b/etcdctl/ctlv3/command/printer_fields.go index 7f2d4e5892d..23e16f3cde8 100644 --- a/etcdctl/ctlv3/command/printer_fields.go +++ b/etcdctl/ctlv3/command/printer_fields.go @@ -137,6 +137,7 @@ func (p *fieldsPrinter) MemberList(r v3.MemberListResponse) { for _, u := range m.ClientURLs { fmt.Printf("\"ClientURL\" : %q\n", u) } + fmt.Println(`"IsLearner" :`, m.IsLearner) fmt.Println() } }