From b433929d42d82e3b9c8b7d624b5d97d078f070d6 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Tue, 4 Feb 2025 14:34:49 +0000 Subject: [PATCH] backport of commit 9367929d87c0a5d654fb4deacfd4f008de6b6a78 --- .changelog/24959.txt | 3 ++ command/job_status.go | 41 ++++++++++++++++++++ website/content/docs/commands/job/status.mdx | 6 ++- website/content/docs/commands/status.mdx | 4 ++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .changelog/24959.txt diff --git a/.changelog/24959.txt b/.changelog/24959.txt new file mode 100644 index 00000000000..9dbf6e522ef --- /dev/null +++ b/.changelog/24959.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Added actions available to a job when running nomad job status command +``` diff --git a/command/job_status.go b/command/job_status.go index 0f444646c87..3ebf483e1c3 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -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" diff --git a/website/content/docs/commands/job/status.mdx b/website/content/docs/commands/job/status.mdx index 7706775ca02..913618847c6 100644 --- a/website/content/docs/commands/job/status.mdx +++ b/website/content/docs/commands/job/status.mdx @@ -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`. @@ -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 diff --git a/website/content/docs/commands/status.mdx b/website/content/docs/commands/status.mdx index db503e1127e..1985812d854 100644 --- a/website/content/docs/commands/status.mdx +++ b/website/content/docs/commands/status.mdx @@ -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