Skip to content

Commit

Permalink
feat: print complete member info in etcd members
Browse files Browse the repository at this point in the history
Fixes: #3487

Example output:

```
NODE       ID                 HOSTNAME                 PEERS                   CLIENTS
10.5.0.2   c3d3020cf75b8728   talos-default-master-1   https://10.5.0.2:2380   https://10.5.0.2:2379
```

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever authored and talos-bot committed Apr 17, 2021
1 parent bb40d6d commit 9a91142
Show file tree
Hide file tree
Showing 5 changed files with 780 additions and 614 deletions.
23 changes: 20 additions & 3 deletions api/machine/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,28 @@ message EtcdForfeitLeadershipResponse {
message EtcdMemberListRequest {
bool query_local = 1;
}
message EtcdMemberList {

// EtcdMember describes a single etcd member.
message EtcdMember {
// member ID.
uint64 id = 2;
// human-readable name of the member.
string hostname = 3;
// the list of URLs the member exposes to clients for communication.
repeated string peer_urls = 4;
// the list of URLs the member exposes to the cluster for communication.
repeated string client_urls = 5;
}

// EtcdMembers contains the list of members registered on the host.
message EtcdMembers {
common.Metadata metadata = 1;
repeated string members = 2;
// list of member hostnames.
repeated string legacy_members = 2;
// the list of etcd members registered on the node.
repeated EtcdMember members = 3;
}
message EtcdMemberListResponse { repeated EtcdMemberList messages = 1; }
message EtcdMemberListResponse { repeated EtcdMembers messages = 1; }

message EtcdSnapshotRequest {}

Expand Down
33 changes: 20 additions & 13 deletions cmd/talosctl/cmd/talos/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"os"
"strconv"
"strings"
"sync"
"text/tabwriter"
Expand Down Expand Up @@ -88,7 +89,7 @@ var etcdMemberListCmd = &cobra.Command{

w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
node := ""
pattern := "%s\t"
pattern := "%s\t%s\t%s\t%s\n"

for i, message := range response.Messages {
if message.Metadata != nil && message.Metadata.Hostname != "" {
Expand All @@ -99,22 +100,28 @@ var etcdMemberListCmd = &cobra.Command{
continue
}

if i == 0 {
for _, member := range message.Members {
if i == 0 {
if node != "" {
fmt.Fprintln(w, "NODE\tID\tHOSTNAME\tPEER URLS\tCLIENT URLS")
pattern = "%s\t" + pattern
} else {
fmt.Fprintln(w, "ID\tHOSTNAME\tPEER URLS\tCLIENT URLS")
}
}

args := []interface{}{
strconv.FormatUint(member.Id, 16),
member.Hostname,
strings.Join(member.PeerUrls, ","),
strings.Join(member.ClientUrls, ","),
}
if node != "" {
fmt.Fprintln(w, "NODE\tMEMBERS")
pattern = "%s\t%s\n"
} else {
fmt.Fprintln(w, "MEMBERS")
args = append([]interface{}{node}, args...)
}
}

args := []interface{}{strings.Join(message.Members, ",")}
if node != "" {
args = append([]interface{}{node}, args...)
fmt.Fprintf(w, pattern, args...)
}

fmt.Fprintf(w, pattern, args...)

}

return w.Flush()
Expand Down
19 changes: 15 additions & 4 deletions internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1698,16 +1698,27 @@ func (s *Server) EtcdMemberList(ctx context.Context, in *machine.EtcdMemberListR
return nil, err
}

members := make([]string, 0, len(resp.Members))
members := make([]*machine.EtcdMember, 0, len(resp.Members))
legacyMembers := make([]string, 0, len(resp.Members))

for _, member := range resp.Members {
members = append(members, member.GetName())
members = append(members,
&machine.EtcdMember{
Id: member.GetID(),
Hostname: member.GetName(),
PeerUrls: member.GetPeerURLs(),
ClientUrls: member.GetClientURLs(),
},
)

legacyMembers = append(legacyMembers, member.GetName())
}

reply = &machine.EtcdMemberListResponse{
Messages: []*machine.EtcdMemberList{
Messages: []*machine.EtcdMembers{
{
Members: members,
LegacyMembers: legacyMembers,
Members: members,
},
},
}
Expand Down
Loading

0 comments on commit 9a91142

Please sign in to comment.