Skip to content

Commit

Permalink
[feat] Make order of admin actions deterministic (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 authored Feb 11, 2024
1 parent 8c8d671 commit d935e85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions internal/tui/components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -755,10 +756,15 @@ func (m Model) getCurrentPageCmd() tea.Cmd {
return func() tea.Msg {
// this does no async work, just constructs the task admin menu
var rows []page.Row
var sortedAllocAdminActions []int
for action := range nomad.AllocAdminActions {
sortedAllocAdminActions = append(sortedAllocAdminActions, int(action))
}
sort.Ints(sortedAllocAdminActions)
for _, action := range sortedAllocAdminActions {
rows = append(rows, page.Row{
Key: nomad.AdminActionToKey(action),
Row: nomad.GetAllocAdminText(action, m.taskName, m.alloc.Name, m.alloc.ID),
Key: nomad.AdminActionToKey(nomad.AdminAction(action)),
Row: nomad.GetAllocAdminText(nomad.AdminAction(action), m.taskName, m.alloc.Name, m.alloc.ID),
})
}
return nomad.PageLoadedMsg{
Expand All @@ -785,10 +791,15 @@ func (m Model) getCurrentPageCmd() tea.Cmd {
return func() tea.Msg {
// this does no async work, just constructs the job admin menu
var rows []page.Row
var sortedJobAdminActions []int
for action := range nomad.JobAdminActions {
sortedJobAdminActions = append(sortedJobAdminActions, int(action))
}
sort.Ints(sortedJobAdminActions)
for _, action := range sortedJobAdminActions {
rows = append(rows, page.Row{
Key: nomad.AdminActionToKey(action),
Row: nomad.GetJobAdminText(action, m.jobID),
Key: nomad.AdminActionToKey(nomad.AdminAction(action)),
Row: nomad.GetJobAdminText(nomad.AdminAction(action), m.jobID),
})
}
return nomad.PageLoadedMsg{
Expand Down
1 change: 1 addition & 0 deletions internal/tui/nomad/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const keySeparator = "|【=◈︿◈=】|"
type AdminAction int8

// all admin actions, task or job
// the definition order of these is important, as it's used for sorting
const (
RestartTaskAction AdminAction = iota
RestartAllocAction
Expand Down

0 comments on commit d935e85

Please sign in to comment.