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 when reschedule policy for allocation can't be looked up #4647

Merged
merged 1 commit into from
Sep 10, 2018
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
4 changes: 4 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6293,6 +6293,10 @@ func (a *Allocation) NextRescheduleTime() (time.Time, bool) {
// It is calculated according to the delay function and previous reschedule attempts.
func (a *Allocation) NextDelay() time.Duration {
policy := a.ReschedulePolicy()
// Can be nil if the task group was updated to remove its reschedule policy
if policy == nil {
return 0
}
delayDur := policy.Delay
if a.RescheduleTracker == nil || a.RescheduleTracker.Events == nil || len(a.RescheduleTracker.Events) == 0 {
return delayDur
Expand Down
10 changes: 9 additions & 1 deletion nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,12 @@ func TestAllocation_NextDelay(t *testing.T) {
expectedRescheduleTime: time.Time{},
expectedRescheduleEligible: false,
},
{
desc: "Allocation has no reschedule policy",
alloc: &Allocation{},
expectedRescheduleTime: time.Time{},
expectedRescheduleEligible: false,
},
{
desc: "Allocation lacks task state",
reschedulePolicy: &ReschedulePolicy{
Expand Down Expand Up @@ -3385,7 +3391,9 @@ func TestAllocation_NextDelay(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
require := require.New(t)
j := testJob()
j.TaskGroups[0].ReschedulePolicy = tc.reschedulePolicy
if tc.reschedulePolicy != nil {
j.TaskGroups[0].ReschedulePolicy = tc.reschedulePolicy
}
tc.alloc.Job = j
tc.alloc.TaskGroup = j.TaskGroups[0].Name
reschedTime, allowed := tc.alloc.NextRescheduleTime()
Expand Down