From ed9786c95747976b7ffd260d4dbb5e2387782149 Mon Sep 17 00:00:00 2001 From: hc-github-team-nomad-core <82989552+hc-github-team-nomad-core@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:05:59 -0600 Subject: [PATCH] backport of commit 557b4942d0f1959bb8509ff9303fa0baa37c0276 (#19116) Co-authored-by: codenoid <14269809+codenoid@users.noreply.github.com> --- .changelog/19115.txt | 3 +++ api/allocations.go | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changelog/19115.txt diff --git a/.changelog/19115.txt b/.changelog/19115.txt new file mode 100644 index 000000000..e279770f0 --- /dev/null +++ b/.changelog/19115.txt @@ -0,0 +1,3 @@ +```release-note:bug +api: Fix panic in `Allocation.Stub` method when `Job` is unset +``` diff --git a/api/allocations.go b/api/allocations.go index 121a75934..800168c80 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -311,7 +311,7 @@ type NodeScoreMeta struct { // Stub returns a list stub for the allocation func (a *Allocation) Stub() *AllocationListStub { - return &AllocationListStub{ + stub := &AllocationListStub{ ID: a.ID, EvalID: a.EvalID, Name: a.Name, @@ -319,8 +319,6 @@ func (a *Allocation) Stub() *AllocationListStub { NodeID: a.NodeID, NodeName: a.NodeName, JobID: a.JobID, - JobType: *a.Job.Type, - JobVersion: *a.Job.Version, TaskGroup: a.TaskGroup, DesiredStatus: a.DesiredStatus, DesiredDescription: a.DesiredDescription, @@ -338,6 +336,13 @@ func (a *Allocation) Stub() *AllocationListStub { CreateTime: a.CreateTime, ModifyTime: a.ModifyTime, } + + if a.Job != nil { + stub.JobType = *a.Job.Type + stub.JobVersion = *a.Job.Version + } + + return stub } // ServerTerminalStatus returns true if the desired state of the allocation is