Skip to content

Commit

Permalink
Merge pull request #258 from wanjunlei/release-2.5
Browse files Browse the repository at this point in the history
fix bug regex silence will silence all alert
  • Loading branch information
benjaminhuo authored Apr 3, 2024
2 parents 6a0dfc0 + 999abcc commit 968be27
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions apis/v2beta2/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ const (
)

func (ls *LabelSelector) Matches(label map[string]string) (bool, error) {
if label == nil {
return false, nil
}

selector := &metav1.LabelSelector{
MatchLabels: ls.MatchLabels,
}

for _, requirement := range ls.MatchExpressions {
if requirement.Operator != LabelSelectorOpMatch {
selector.MatchExpressions = append(selector.MatchExpressions, metav1.LabelSelectorRequirement{
Expand All @@ -54,11 +57,9 @@ func (ls *LabelSelector) Matches(label map[string]string) (bool, error) {
Values: requirement.Values,
})
} else {
if v, ok := label[requirement.Key]; ok {
match, err := regexp.MatchString(requirement.RegexValue, v)
if err != nil || !match {
return false, err
}
match, err := regexp.MatchString(requirement.RegexValue, label[requirement.Key])
if !match {
return false, err
}
}
}
Expand Down

0 comments on commit 968be27

Please sign in to comment.