[cli] Adds Actions to job status command output (#24959)

* Adds Actions to job status command output

* Adds Actions to job status command output

* Status documentation updated to show actions and formatJobActions no longer cares about pipe delineation
This commit is contained in:
Phil Renaud
2025-02-04 09:34:49 -05:00
committed by GitHub
parent 389f4612b6
commit 9367929d87
4 changed files with 53 additions and 1 deletions

3
.changelog/24959.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
cli: Added actions available to a job when running nomad job status command
```

View File

@@ -406,6 +406,19 @@ func (c *JobStatusCommand) outputJobInfo(client *api.Client, job *api.Job) error
return fmt.Errorf("Error querying latest job deployment: %s", err)
}
jobActions := make([]map[string]string, 0)
for _, tg := range job.TaskGroups {
for _, task := range tg.Tasks {
for _, action := range task.Actions {
jobActions = append(jobActions, map[string]string{
"group": *tg.Name,
"task": task.Name,
"action": action.Name,
})
}
}
}
// Output the summary
if err := c.outputJobSummary(client, job); err != nil {
return err
@@ -459,6 +472,11 @@ func (c *JobStatusCommand) outputJobInfo(client *api.Client, job *api.Job) error
c.Ui.Output(c.Colorize().Color(c.formatDeployment(client, latestDeployment)))
}
if len(jobActions) > 0 {
c.Ui.Output(c.Colorize().Color("\n[bold]Actions[reset]"))
c.Ui.Output(formatJobActions(jobActions))
}
// Format the allocs
c.Ui.Output(c.Colorize().Color("\n[bold]Allocations[reset]"))
c.Ui.Output(formatAllocListStubs(jobAllocs, c.verbose, c.length))
@@ -493,6 +511,29 @@ func (c *JobStatusCommand) formatDeployment(client *api.Client, d *api.Deploymen
return base
}
func formatJobActions(actions []map[string]string) string {
if len(actions) == 0 {
return "No actions configured"
}
actionsOut := make([]string, len(actions)+1)
actionsOut[0] = "Action Name|Task Group|Task"
for i, action := range actions {
group, task, actionName := action["group"], action["task"], action["action"]
if group == "" || task == "" || actionName == "" {
continue
}
actionsOut[i+1] = fmt.Sprintf("%s|%s|%s",
actionName,
group,
task)
}
return formatList(actionsOut)
}
func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLength int) string {
if len(stubs) == 0 {
return "No allocations placed"

View File

@@ -105,6 +105,10 @@ Deployed
Task Group Desired Placed Healthy Unhealthy
cache 1 1 1 0
Actions
Action Name Task Group Task
my-action cache my-task
Allocations
ID Node ID Task Group Version Desired Status Created Modified
478ce836 5ed166e8 cache 0 run running 5m ago 5m ago

View File

@@ -55,6 +55,10 @@ Deployed
Task Group Desired Placed Healthy Unhealthy
cache 1 1 0 0
Actions
Action Name Task Group Task
my-action cache my-task
Allocations
ID Node ID Task Group Version Desired Status Created At
e1d14a39 f9dabe93 cache 0 run running 08/28/17 23:01:39 UTC