Skip to content

Commit

Permalink
fix bug regex silence will silence all alert
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
  • Loading branch information
wanjunlei committed Apr 3, 2024
1 parent 6a0dfc0 commit 999abcc
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 999abcc

Please sign in to comment.