From 01f7d8c24e227470b4cb6009d6da7497d918b362 Mon Sep 17 00:00:00 2001 From: Daniel Bennett Date: Tue, 9 Apr 2024 16:11:25 -0400 Subject: [PATCH] add LatestDeployment probably will remove ActiveDeploymentID later --- nomad/jobs_endpoint.go | 13 ++++++++++++- nomad/structs/job.go | 11 +++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nomad/jobs_endpoint.go b/nomad/jobs_endpoint.go index cf426896b834..2943bfea766b 100644 --- a/nomad/jobs_endpoint.go +++ b/nomad/jobs_endpoint.go @@ -294,7 +294,7 @@ func UIJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *structs.Job, uiJob.Allocs = append(uiJob.Allocs, alloc) } - // look for active deployment + // look for latest deployment deploy, err := store.LatestDeploymentByJobID(ws, job.Namespace, job.ID) if err != nil { return uiJob, idx, err @@ -303,6 +303,17 @@ func UIJobFromJob(ws memdb.WatchSet, store *state.StateStore, job *structs.Job, if deploy.Active() { uiJob.ActiveDeploymentID = deploy.ID } + + uiJob.LatestDeployment = &structs.JobStatusLatestDeployment{ + ID: deploy.ID, + IsActive: deploy.Active(), + JobVersion: deploy.JobVersion, + Status: deploy.Status, + StatusDescription: deploy.StatusDescription, + AllAutoPromote: deploy.HasAutoPromote(), + RequiresPromotion: deploy.RequiresPromotion(), + } + if deploy.ModifyIndex > idx { idx = deploy.ModifyIndex } diff --git a/nomad/structs/job.go b/nomad/structs/job.go index 174359f952fa..96b710b530cb 100644 --- a/nomad/structs/job.go +++ b/nomad/structs/job.go @@ -28,6 +28,7 @@ type UIJob struct { GroupCountSum int ChildStatuses []string ActiveDeploymentID string + LatestDeployment *JobStatusLatestDeployment Version uint64 SubmitTime int64 ModifyIndex uint64 @@ -58,6 +59,16 @@ type JobStatusDeployment struct { Healthy bool } +type JobStatusLatestDeployment struct { + ID string + IsActive bool + JobVersion uint64 + Status string + StatusDescription string + AllAutoPromote bool + RequiresPromotion bool +} + // JobServiceRegistrationsRequest is the request object used to list all // service registrations belonging to the specified Job.ID. type JobServiceRegistrationsRequest struct {