Daemon: don't return not matched labels when searching
This commit is contained in:
parent
f60f92d667
commit
128ed765e7
@ -155,19 +155,24 @@ func (d *Discoveries) Filter(labelsFilter []string) []Discovery {
|
|||||||
var found bool
|
var found bool
|
||||||
if len(labelsFilter) > 0 {
|
if len(labelsFilter) > 0 {
|
||||||
for _, discovery := range d.activeServers {
|
for _, discovery := range d.activeServers {
|
||||||
|
newDiscovery := discovery
|
||||||
|
newDiscovery.Labels = Labels{}
|
||||||
|
|
||||||
found = false
|
found = false
|
||||||
for _, label := range discovery.Labels {
|
for _, label := range discovery.Labels {
|
||||||
for _, labelFilter := range labelsFilter {
|
for _, labelFilter := range labelsFilter {
|
||||||
if label.String() == labelFilter {
|
if label.String() == labelFilter {
|
||||||
newSet = append(newSet, discovery)
|
|
||||||
found = true
|
found = true
|
||||||
|
newDiscovery.Labels = append(newDiscovery.Labels, label)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
break
|
newSet = append(newSet, newDiscovery)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -182,18 +187,27 @@ func (d *Discoveries) FilterPrefix(prefixes []string) []Discovery {
|
|||||||
var found bool
|
var found bool
|
||||||
if len(prefixes) > 0 {
|
if len(prefixes) > 0 {
|
||||||
for _, discovery := range d.activeServers {
|
for _, discovery := range d.activeServers {
|
||||||
|
newDiscovery := discovery
|
||||||
|
newDiscovery.Labels = Labels{}
|
||||||
|
|
||||||
found = false
|
found = false
|
||||||
|
|
||||||
|
if found {
|
||||||
|
newSet = append(newSet, newDiscovery)
|
||||||
|
}
|
||||||
|
|
||||||
for _, label := range discovery.Labels {
|
for _, label := range discovery.Labels {
|
||||||
for _, prefix := range prefixes {
|
for _, prefix := range prefixes {
|
||||||
if strings.HasPrefix(label.String(), prefix) {
|
if strings.HasPrefix(label.String(), prefix) {
|
||||||
newSet = append(newSet, discovery)
|
|
||||||
found = true
|
found = true
|
||||||
|
newDiscovery.Labels = append(newDiscovery.Labels, label)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
break
|
newSet = append(newSet, newDiscovery)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user