cli: show leader status in json output of server members (#17138)

This commit is contained in:
Yethal 2023-05-18 22:43:57 +02:00 committed by GitHub
parent 7e56ca62d1
commit 4073987de3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

3
.changelog/17138.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
cli: Add leader status to output of `nomad server members -json`
```

View File

@ -118,7 +118,13 @@ func (c *ServerMembersCommand) Run(args []string) int {
// Sort the members // Sort the members
sort.Sort(api.AgentMembersNameSort(srvMembers.Members)) sort.Sort(api.AgentMembersNameSort(srvMembers.Members))
// Determine the leaders per region.
leaders, leaderErr := regionLeaders(client, srvMembers.Members)
if json || len(tmpl) > 0 { if json || len(tmpl) > 0 {
for _, member := range srvMembers.Members {
member.Tags["Leader"] = fmt.Sprintf("%t", isLeader(member, leaders))
}
out, err := Format(json, tmpl, srvMembers.Members) out, err := Format(json, tmpl, srvMembers.Members)
if err != nil { if err != nil {
c.Ui.Error(err.Error()) c.Ui.Error(err.Error())
@ -129,9 +135,6 @@ func (c *ServerMembersCommand) Run(args []string) int {
return 0 return 0
} }
// Determine the leaders per region.
leaders, leaderErr := regionLeaders(client, srvMembers.Members)
// Format the list // Format the list
var out []string var out []string
if verbose { if verbose {