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 prohibiting Nomad Job recreation with delay in between #680

Merged
merged 1 commit into from
Sep 5, 2024
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
26 changes: 26 additions & 0 deletions internal/nomad/event_stream_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,32 @@ func (s *MainTestSuite) TestAPIClient_WatchAllocationsReturnsErrorOnUnexpectedEO
s.Equal(1, eventsProcessed)
}

func (s *MainTestSuite) TestAPIClient_WatchAllocationsReturnsLocalDestroyReasonOnStoppingAllocation() {
pendingAllocation := createRecentAllocation(structs.AllocClientStatusPending, structs.AllocDesiredStatusRun)
startedAllocation := createRecentAllocation(structs.AllocClientStatusRunning, structs.AllocDesiredStatusRun)
stoppingAllocation := createRecentAllocation(structs.AllocClientStatusRunning, structs.AllocDesiredStatusStop)
events := nomadApi.Events{Events: []nomadApi.Event{
eventForAllocation(s.T(), pendingAllocation),
eventForAllocation(s.T(), startedAllocation),
eventForAllocation(s.T(), stoppingAllocation),
}}

callbackCalled := false
callbacks := &AllocationProcessing{
OnNew: func(_ context.Context, _ *nomadApi.Allocation, _ time.Duration) {},
OnDeleted: func(_ context.Context, jobID string, reason error) bool {
callbackCalled = true
s.Equal(tests.DefaultRunnerID, jobID)
s.ErrorIs(reason, ErrLocalDestruction)
return false
},
}

_, err := runAllocationWatching(s, []*nomadApi.Events{&events}, callbacks)
s.Require().NoError(err)
s.True(callbackCalled)
}

func (s *MainTestSuite) TestAPIClient_WatchAllocationsCanHandleMigration() {
jobID := "10-0331c7d8-03c1-11ef-b832-fa163e7afdf8"
a1ID := "84a734a1-5573-6116-5678-86060ce4c479"
Expand Down
3 changes: 2 additions & 1 deletion internal/nomad/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var (
"%w correctly but rescheduled", ErrAllocationStopped)
// ErrAllocationCompleted is for reporting the reason for the stopped allocation.
// We do not consider it as an error but add it anyway for a complete reporting.
ErrAllocationCompleted RunnerDeletedReason = errors.New("the allocation completed")
// It is a ErrLocalDestruction because another allocation might be replacing the allocation in the same job.
ErrAllocationCompleted RunnerDeletedReason = fmt.Errorf("the allocation completed: %w", ErrLocalDestruction)
)

type RunnerDeletedReason error
Expand Down
Loading