Fix multiple user Runner use

A before unknown Nomad reload adds already known runner again to the idle runner - even if they are already in use.
This commit is contained in:
Maximilian Paß
2023-03-15 09:16:52 +00:00
committed by Sebastian Serth
parent 0d829c9308
commit e0db1bafe8
3 changed files with 18 additions and 3 deletions

View File

@ -146,6 +146,11 @@ func (m *NomadRunnerManager) onAllocationAdded(alloc *nomadApi.Allocation, start
return
}
if _, ok := m.usedRunners.Get(alloc.JobID); ok {
log.WithField("id", alloc.JobID).Debug("Started Runner is already in use")
return
}
environmentID, err := nomad.EnvironmentIDFromRunnerID(alloc.JobID)
if err != nil {
log.WithError(err).Warn("Allocation could not be added")

View File

@ -321,19 +321,29 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
s.True(ok)
mockIdleRunners(environment.(*ExecutionEnvironmentMock))
_, ok = environment.Sample()
s.Require().False(ok)
alloc := &nomadApi.Allocation{
JobID: tests.DefaultRunnerID,
AllocatedResources: nil,
}
s.nomadRunnerManager.onAllocationAdded(alloc, 0)
runner, ok := environment.Sample()
s.True(ok)
runner, err := s.nomadRunnerManager.Claim(defaultEnvironmentID, defaultInactivityTimeout)
s.NoError(err)
nomadJob, ok := runner.(*NomadJob)
s.True(ok)
s.Equal(nomadJob.id, tests.DefaultRunnerID)
s.Empty(nomadJob.portMappings)
s.Run("but not again", func() {
s.nomadRunnerManager.onAllocationAdded(alloc, 0)
runner, err = s.nomadRunnerManager.Claim(defaultEnvironmentID, defaultInactivityTimeout)
s.Error(err)
})
})
s.nomadRunnerManager.usedRunners.Purge()
s.Run("with mapped ports", func() {
environment, ok := s.nomadRunnerManager.environments.Get(tests.DefaultEnvironmentIDAsString)
s.True(ok)

View File

@ -166,7 +166,7 @@ func WriteInfluxPoint(p *write.Point) {
for _, field := range p.FieldList() {
entry = entry.WithField(field.Key, field.Value)
}
entry.Debug("Influx data point")
entry.Trace("Influx data point")
}
}