Skip to content

Commit

Permalink
Merge pull request kubesphere#257 from wanjunlei/master
Browse files Browse the repository at this point in the history
fix bug regex silence will silence all alert
  • Loading branch information
benjaminhuo committed Apr 3, 2024
2 parents acf51eb + 45ca199 commit 0c0535a
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 0c0535a

Please sign in to comment.