Skip to content

Commit

Permalink
Merge pull request #3137 from hashicorp/b-deployment-ordering
Browse files Browse the repository at this point in the history
Sort task groups when displaying a deployment
  • Loading branch information
dadgar authored Aug 30, 2017
2 parents 2f10b9f + 84c46cb commit ea4f1c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BUG FIXES:
* api: Search handles prefix longer than allowed UUIDs [GH-3138]
* api: Search endpoint handles even UUID prefixes with hyphens [GH-3120]
* cli: Sort task groups when displaying a deployment [GH-3137]
* api: Don't merge empty update stanza from job into task groups [GH-3139]
* cli: All status commands handle even UUID prefixes with hyphens [GH-3122]
* cli: Fix autocompletion of paths that include directories on zsh [GH-3129]
Expand Down
11 changes: 9 additions & 2 deletions command/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"fmt"
"sort"
"strings"

"github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -189,7 +190,9 @@ func formatDeployment(d *api.Deployment, uuidLength int) string {
func formatDeploymentGroups(d *api.Deployment, uuidLength int) string {
// Detect if we need to add these columns
canaries, autorevert := false, false
for _, state := range d.TaskGroups {
tgNames := make([]string, 0, len(d.TaskGroups))
for name, state := range d.TaskGroups {
tgNames = append(tgNames, name)
if state.AutoRevert {
autorevert = true
}
Expand All @@ -198,6 +201,9 @@ func formatDeploymentGroups(d *api.Deployment, uuidLength int) string {
}
}

// Sort the task group names to get a reliable ordering
sort.Strings(tgNames)

// Build the row string
rowString := "Task Group|"
if autorevert {
Expand All @@ -215,7 +221,8 @@ func formatDeploymentGroups(d *api.Deployment, uuidLength int) string {
rows := make([]string, len(d.TaskGroups)+1)
rows[0] = rowString
i := 1
for tg, state := range d.TaskGroups {
for _, tg := range tgNames {
state := d.TaskGroups[tg]
row := fmt.Sprintf("%s|", tg)
if autorevert {
row += fmt.Sprintf("%v|", state.AutoRevert)
Expand Down

0 comments on commit ea4f1c2

Please sign in to comment.