Skip to content

Commit

Permalink
[cli] Adds Actions to job status command output (#24959)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
philrenaud authored Feb 4, 2025
1 parent 389f461 commit 9367929
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/24959.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Added actions available to a job when running nomad job status command
```
41 changes: 41 additions & 0 deletions command/job_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion website/content/docs/commands/job/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ the specific job is queried and displayed. Otherwise, a list of matching jobs
and information will be displayed.

If the ID is omitted, the command lists out all of the existing jobs and a few
of the most useful status fields for each. Alloc status also shows allocation
of the most useful status fields for each. Alloc status also shows allocation
modification time in addition to create time. When the `-verbose` flag is not set,
allocation creation and modify times are shown in a shortened relative time format
like `5m ago`.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions website/content/docs/commands/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9367929

Please sign in to comment.