From af48549f38ec207ded1e7988fa176a58457b7878 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Fri, 26 Jan 2024 20:49:31 +0100 Subject: [PATCH] chore: dont rely on slice labels Signed-off-by: Michael Hoffmann --- injectproxy/rules.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/injectproxy/rules.go b/injectproxy/rules.go index 30ac5148..e85f7e45 100644 --- a/injectproxy/rules.go +++ b/injectproxy/rules.go @@ -207,11 +207,8 @@ func (r *routes) filterRules(lvalues []string, resp *apiResponse) (interface{}, for _, rg := range rgs.RuleGroups { var rules []rule for _, rule := range rg.Rules { - for _, lbl := range rule.Labels() { - if lbl.Name == r.label && slices.Contains(lvalues, lbl.Value) { - rules = append(rules, rule) - break - } + if rule.Labels().Has(r.label) && slices.Contains(lvalues, rule.Labels().Get(r.label)) { + rules = append(rules, rule) } } if len(rules) > 0 { @@ -231,11 +228,8 @@ func (r *routes) filterAlerts(lvalues []string, resp *apiResponse) (interface{}, filtered := []*alert{} for _, alert := range data.Alerts { - for _, lbl := range alert.Labels { - if lbl.Name == r.label && slices.Contains(lvalues, lbl.Value) { - filtered = append(filtered, alert) - break - } + if alert.Labels.Has(r.label) && slices.Contains(lvalues, alert.Labels.Get(r.label)) { + filtered = append(filtered, alert) } }