Daemon: don't return not matched labels when searching

This commit is contained in:
Adam Štrauch 2021-09-05 22:00:08 +02:00
parent f60f92d667
commit 128ed765e7
Signed by: cx
GPG Key ID: 018304FFA8988F8D

View File

@ -155,19 +155,24 @@ func (d *Discoveries) Filter(labelsFilter []string) []Discovery {
var found bool
if len(labelsFilter) > 0 {
for _, discovery := range d.activeServers {
newDiscovery := discovery
newDiscovery.Labels = Labels{}
found = false
for _, label := range discovery.Labels {
for _, labelFilter := range labelsFilter {
if label.String() == labelFilter {
newSet = append(newSet, discovery)
found = true
newDiscovery.Labels = append(newDiscovery.Labels, label)
break
}
}
}
if found {
break
}
newSet = append(newSet, newDiscovery)
}
}
}
@ -182,18 +187,27 @@ func (d *Discoveries) FilterPrefix(prefixes []string) []Discovery {
var found bool
if len(prefixes) > 0 {
for _, discovery := range d.activeServers {
newDiscovery := discovery
newDiscovery.Labels = Labels{}
found = false
if found {
newSet = append(newSet, newDiscovery)
}
for _, label := range discovery.Labels {
for _, prefix := range prefixes {
if strings.HasPrefix(label.String(), prefix) {
newSet = append(newSet, discovery)
found = true
newDiscovery.Labels = append(newDiscovery.Labels, label)
break
}
}
}
if found {
break
}
newSet = append(newSet, newDiscovery)
}
}