remove group if the target is empty at adapter level

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
Augustin Husson 2018-09-16 14:36:09 +02:00
parent 9970e4e7e4
commit 97950a3fae
2 changed files with 6 additions and 5 deletions

View File

@ -232,11 +232,6 @@ func (m *Manager) updateGroup(poolKey poolKey, tgs []*targetgroup.Group) {
m.targets[poolKey] = make(map[string]*targetgroup.Group) m.targets[poolKey] = make(map[string]*targetgroup.Group)
} }
m.targets[poolKey][tg.Source] = tg m.targets[poolKey][tg.Source] = tg
// Clear the key in the case where the targets is empty.
if tg.Targets == nil || len(tg.Targets) <= 0 {
delete(m.targets[poolKey], tg.Source)
}
} }
} }
} }

View File

@ -60,6 +60,12 @@ func (a *Adapter) generateTargetGroups(allTargetGroups map[string][]*targetgroup
tempGroups := make(map[string]*customSD) tempGroups := make(map[string]*customSD)
for k, sdTargetGroups := range allTargetGroups { for k, sdTargetGroups := range allTargetGroups {
for i, group := range sdTargetGroups { for i, group := range sdTargetGroups {
// There is no target, so no need to keep it
if len(group.Targets) <= 0 {
continue
}
newTargets := make([]string, 0) newTargets := make([]string, 0)
newLabels := make(map[string]string) newLabels := make(map[string]string)