some Discoverers send nil targetgroup so need to check for it when updating a group
This commit is contained in:
parent
7e28397a2c
commit
638818a974
|
@ -158,16 +158,18 @@ func (m *Manager) cancelDiscoverers() {
|
|||
m.discoverCancel = nil
|
||||
}
|
||||
|
||||
func (m *Manager) updateGroup(poolKey poolKey, tg []*targetgroup.Group) {
|
||||
func (m *Manager) updateGroup(poolKey poolKey, tgs []*targetgroup.Group) {
|
||||
done := make(chan struct{})
|
||||
|
||||
m.actionCh <- func(ctx context.Context) {
|
||||
if tg != nil {
|
||||
for _, t := range tg {
|
||||
if tgs != nil {
|
||||
for _, tg := range tgs {
|
||||
if tg != nil { // Some Discoverers send nil targetgroup so need to check for it to avoid panics.
|
||||
if _, ok := m.targets[poolKey]; !ok {
|
||||
m.targets[poolKey] = make(map[string]*targetgroup.Group)
|
||||
}
|
||||
m.targets[poolKey][t.Source] = t
|
||||
m.targets[poolKey][tg.Source] = tg
|
||||
}
|
||||
}
|
||||
}
|
||||
close(done)
|
||||
|
@ -191,13 +193,9 @@ func (m *Manager) allGroups() map[string][]*targetgroup.Group {
|
|||
tSetsAll := map[string][]*targetgroup.Group{}
|
||||
for _, pk := range pKeys {
|
||||
for _, tg := range m.targets[pk] {
|
||||
// Don't add empty targets.
|
||||
// Some Discoverers(eg. k8s) send only the updates so removed targets will be updated with an empty Source value.
|
||||
if tg.Source != "" {
|
||||
tSetsAll[pk.setName] = append(tSetsAll[pk.setName], tg)
|
||||
}
|
||||
}
|
||||
}
|
||||
tSets <- tSetsAll
|
||||
}
|
||||
return <-tSets
|
||||
|
|
Loading…
Reference in New Issue