backport of commit 557b4942d0f1959bb8509ff9303fa0baa37c0276 (#19116)

Co-authored-by: codenoid <14269809+codenoid@users.noreply.github.com>
This commit is contained in:
hc-github-team-nomad-core 2023-11-17 08:05:59 -06:00 committed by GitHub
parent 7057c0c886
commit ed9786c957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

3
.changelog/19115.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
api: Fix panic in `Allocation.Stub` method when `Job` is unset
```

View File

@ -311,7 +311,7 @@ type NodeScoreMeta struct {
// Stub returns a list stub for the allocation // Stub returns a list stub for the allocation
func (a *Allocation) Stub() *AllocationListStub { func (a *Allocation) Stub() *AllocationListStub {
return &AllocationListStub{ stub := &AllocationListStub{
ID: a.ID, ID: a.ID,
EvalID: a.EvalID, EvalID: a.EvalID,
Name: a.Name, Name: a.Name,
@ -319,8 +319,6 @@ func (a *Allocation) Stub() *AllocationListStub {
NodeID: a.NodeID, NodeID: a.NodeID,
NodeName: a.NodeName, NodeName: a.NodeName,
JobID: a.JobID, JobID: a.JobID,
JobType: *a.Job.Type,
JobVersion: *a.Job.Version,
TaskGroup: a.TaskGroup, TaskGroup: a.TaskGroup,
DesiredStatus: a.DesiredStatus, DesiredStatus: a.DesiredStatus,
DesiredDescription: a.DesiredDescription, DesiredDescription: a.DesiredDescription,
@ -338,6 +336,13 @@ func (a *Allocation) Stub() *AllocationListStub {
CreateTime: a.CreateTime, CreateTime: a.CreateTime,
ModifyTime: a.ModifyTime, 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 // ServerTerminalStatus returns true if the desired state of the allocation is