From 90d591d4ec0bee36c2fd07baf5e10d4bbac36848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Sun, 17 Sep 2023 18:57:52 +0200 Subject: [PATCH] Change default behavior in Nomad Event Handling to not propagate that pending runners are being stopped. --- internal/nomad/nomad.go | 3 ++- internal/nomad/nomad_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/nomad/nomad.go b/internal/nomad/nomad.go index 3e323c2..2f9b0ef 100644 --- a/internal/nomad/nomad.go +++ b/internal/nomad/nomad.go @@ -453,7 +453,8 @@ func handlePendingAllocationEvent(alloc *nomadApi.Allocation, allocData *allocat stopExpected: stopExpected, }) case structs.AllocDesiredStatusStop: - handleStoppingAllocationEvent(alloc, allocations, callbacks, false) + // As this allocation was still pending, we don't have to propagate its deletion. + allocations.Delete(alloc.ID) // Anyway, we want to monitor the occurrences. if !allocData.stopExpected { log.WithField("alloc", alloc).Warn("Pending allocation was stopped unexpectedly") diff --git a/internal/nomad/nomad_test.go b/internal/nomad/nomad_test.go index 25a290b..9321a87 100644 --- a/internal/nomad/nomad_test.go +++ b/internal/nomad/nomad_test.go @@ -518,9 +518,9 @@ func (s *MainTestSuite) TestApiClient_WatchAllocationsUsesCallbacksForEvents() { stoppedPendingAllocation := createRecentAllocation(structs.AllocClientStatusPending, structs.AllocDesiredStatusStop) stoppedPendingEvents := nomadApi.Events{Events: []nomadApi.Event{eventForAllocation(s.T(), stoppedPendingAllocation)}} - s.Run("it removes stopped pending allocations", func() { + s.Run("it does not callback for stopped pending allocations", func() { assertWatchAllocation(s, []*nomadApi.Events{&pendingEvents, &stoppedPendingEvents}, - []*nomadApi.Allocation(nil), []string{stoppedPendingAllocation.JobID}) + []*nomadApi.Allocation(nil), []string(nil)) }) failedAllocation := createRecentAllocation(structs.AllocClientStatusFailed, structs.AllocDesiredStatusStop)