Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in Allocation.Stub() when Job is nil #19115

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19115.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api: Fix panic in `Allocation.Stub` method when `Job` is unset
```
11 changes: 8 additions & 3 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,14 @@ 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,
Namespace: a.Namespace,
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,
Expand All @@ -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
Expand Down