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:

committed by
Sebastian Serth

parent
0d829c9308
commit
e0db1bafe8
@ -146,6 +146,11 @@ func (m *NomadRunnerManager) onAllocationAdded(alloc *nomadApi.Allocation, start
|
|||||||
return
|
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)
|
environmentID, err := nomad.EnvironmentIDFromRunnerID(alloc.JobID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Warn("Allocation could not be added")
|
log.WithError(err).Warn("Allocation could not be added")
|
||||||
|
@ -321,19 +321,29 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
|
|||||||
s.True(ok)
|
s.True(ok)
|
||||||
mockIdleRunners(environment.(*ExecutionEnvironmentMock))
|
mockIdleRunners(environment.(*ExecutionEnvironmentMock))
|
||||||
|
|
||||||
|
_, ok = environment.Sample()
|
||||||
|
s.Require().False(ok)
|
||||||
|
|
||||||
alloc := &nomadApi.Allocation{
|
alloc := &nomadApi.Allocation{
|
||||||
JobID: tests.DefaultRunnerID,
|
JobID: tests.DefaultRunnerID,
|
||||||
AllocatedResources: nil,
|
AllocatedResources: nil,
|
||||||
}
|
}
|
||||||
s.nomadRunnerManager.onAllocationAdded(alloc, 0)
|
s.nomadRunnerManager.onAllocationAdded(alloc, 0)
|
||||||
|
|
||||||
runner, ok := environment.Sample()
|
runner, err := s.nomadRunnerManager.Claim(defaultEnvironmentID, defaultInactivityTimeout)
|
||||||
s.True(ok)
|
s.NoError(err)
|
||||||
nomadJob, ok := runner.(*NomadJob)
|
nomadJob, ok := runner.(*NomadJob)
|
||||||
s.True(ok)
|
s.True(ok)
|
||||||
s.Equal(nomadJob.id, tests.DefaultRunnerID)
|
s.Equal(nomadJob.id, tests.DefaultRunnerID)
|
||||||
s.Empty(nomadJob.portMappings)
|
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() {
|
s.Run("with mapped ports", func() {
|
||||||
environment, ok := s.nomadRunnerManager.environments.Get(tests.DefaultEnvironmentIDAsString)
|
environment, ok := s.nomadRunnerManager.environments.Get(tests.DefaultEnvironmentIDAsString)
|
||||||
s.True(ok)
|
s.True(ok)
|
||||||
|
@ -166,7 +166,7 @@ func WriteInfluxPoint(p *write.Point) {
|
|||||||
for _, field := range p.FieldList() {
|
for _, field := range p.FieldList() {
|
||||||
entry = entry.WithField(field.Key, field.Value)
|
entry = entry.WithField(field.Key, field.Value)
|
||||||
}
|
}
|
||||||
entry.Debug("Influx data point")
|
entry.Trace("Influx data point")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user