From 4dfdf2f557c2f8c881029b385ec2edd3c54223f4 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Thu, 20 Jun 2024 15:43:32 -0400 Subject: [PATCH 1/2] Pack metadata booleanified and added to the statuses endpoint --- nomad/job_endpoint_statuses.go | 12 ++++++++++++ nomad/structs/job.go | 1 + ui/app/components/child-job-row.hbs | 2 +- ui/app/models/job.js | 4 +--- ui/app/templates/jobs/index.hbs | 3 +-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nomad/job_endpoint_statuses.go b/nomad/job_endpoint_statuses.go index d55ae7c366b..e2a3c9f967c 100644 --- a/nomad/job_endpoint_statuses.go +++ b/nomad/job_endpoint_statuses.go @@ -6,6 +6,7 @@ package nomad import ( "errors" "net/http" + "strings" "time" "github.com/armon/go-metrics" @@ -198,6 +199,16 @@ func (j *Job) Statuses( func jobStatusesJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *structs.Job) (structs.JobStatusesJob, uint64, error) { highestIdx := job.ModifyIndex + isPack := false + if job.Meta != nil { + for key, value := range job.Meta { + if strings.HasPrefix(key, "pack") && value != "" { + isPack = true + break + } + } + } + jsj := structs.JobStatusesJob{ NamespacedID: structs.NamespacedID{ ID: job.ID, @@ -219,6 +230,7 @@ func jobStatusesJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *stru LatestDeployment: nil, Stop: job.Stop, Status: job.Status, + IsPack: isPack, } // the GroupCountSum will map to how many allocations we expect to run diff --git a/nomad/structs/job.go b/nomad/structs/job.go index 93ca19a9f75..7b8ea4b8f03 100644 --- a/nomad/structs/job.go +++ b/nomad/structs/job.go @@ -98,6 +98,7 @@ type JobStatusesJob struct { ParentID string LatestDeployment *JobStatusesLatestDeployment Stop bool // has the job been manually stopped? + IsPack bool // is pack metadata present? Status string } diff --git a/ui/app/components/child-job-row.hbs b/ui/app/components/child-job-row.hbs index 08883a55d62..b97f4eae584 100644 --- a/ui/app/components/child-job-row.hbs +++ b/ui/app/components/child-job-row.hbs @@ -17,7 +17,7 @@ > {{@job.name}} - {{#if @job.meta.structured.pack}} + {{#if @job.isPack}} {{x-icon "box" class= "test"}} Pack diff --git a/ui/app/models/job.js b/ui/app/models/job.js index 94ff651d286..7d06a0f081d 100644 --- a/ui/app/models/job.js +++ b/ui/app/models/job.js @@ -302,9 +302,7 @@ export default class Job extends Model { } @fragment('structured-attributes') meta; - get isPack() { - return !!this.meta?.structured?.pack; - } + @attr('boolean') isPack; /** * A task with a schedule block can have execution paused at specific cron-based times. diff --git a/ui/app/templates/jobs/index.hbs b/ui/app/templates/jobs/index.hbs index e593ee0a2c3..21a6db3e43d 100644 --- a/ui/app/templates/jobs/index.hbs +++ b/ui/app/templates/jobs/index.hbs @@ -157,8 +157,7 @@ class="is-primary" > {{B.data.name}} - {{!-- TODO: going to lose .meta with statuses endpoint! --}} - {{#if B.data.meta.structured.pack}} + {{#if B.data.isPack}} {{x-icon "box" class= "test"}} Pack From ed028f01894b4f0cf9d939bac3949d766fcdc29c Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 26 Jun 2024 13:50:49 -0400 Subject: [PATCH 2/2] Simplify job.IsPack declaration --- .changelog/23404.txt | 3 +++ nomad/job_endpoint_statuses.go | 14 ++------------ ui/app/routes/jobs/job.js | 1 - 3 files changed, 5 insertions(+), 13 deletions(-) create mode 100644 .changelog/23404.txt diff --git a/.changelog/23404.txt b/.changelog/23404.txt new file mode 100644 index 00000000000..38a15c77521 --- /dev/null +++ b/.changelog/23404.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: added a Pack badge to the jobs index page for jobs run via Nomad Pack +``` diff --git a/nomad/job_endpoint_statuses.go b/nomad/job_endpoint_statuses.go index e2a3c9f967c..c02768fe15b 100644 --- a/nomad/job_endpoint_statuses.go +++ b/nomad/job_endpoint_statuses.go @@ -6,7 +6,6 @@ package nomad import ( "errors" "net/http" - "strings" "time" "github.com/armon/go-metrics" @@ -199,16 +198,6 @@ func (j *Job) Statuses( func jobStatusesJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *structs.Job) (structs.JobStatusesJob, uint64, error) { highestIdx := job.ModifyIndex - isPack := false - if job.Meta != nil { - for key, value := range job.Meta { - if strings.HasPrefix(key, "pack") && value != "" { - isPack = true - break - } - } - } - jsj := structs.JobStatusesJob{ NamespacedID: structs.NamespacedID{ ID: job.ID, @@ -230,9 +219,10 @@ func jobStatusesJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *stru LatestDeployment: nil, Stop: job.Stop, Status: job.Status, - IsPack: isPack, } + _, jsj.IsPack = job.Meta["pack.name"] + // the GroupCountSum will map to how many allocations we expect to run // (for service jobs) for _, tg := range job.TaskGroups { diff --git a/ui/app/routes/jobs/job.js b/ui/app/routes/jobs/job.js index 59656ef3a9d..deb5949d934 100644 --- a/ui/app/routes/jobs/job.js +++ b/ui/app/routes/jobs/job.js @@ -44,7 +44,6 @@ export default class JobRoute extends Route.extend(WithWatchers) { const relatedModelsQueries = [ job.get('allocations'), job.get('evaluations'), - // this.store.query('job', { namespace, meta: true }), // TODO: I think I am probably nuking the ability to get meta:pack info here. See https://github.com/hashicorp/nomad/pull/14833 this.store.findAll('namespace'), ];