From f1c7400493e5171085c27e1e6419c86cf51e8dff Mon Sep 17 00:00:00 2001 From: ivana Date: Fri, 14 Aug 2020 18:07:40 -0400 Subject: [PATCH 1/2] Fix label matching bug Use the configured label value as the regex pattern. Currently it is trying to match the value from the config using the object's label as the pattern, which is incorrect. See also the Annotations matching below which is doing it correctly. --- pkg/exporter/rule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/exporter/rule.go b/pkg/exporter/rule.go index b56cd85..329b792 100644 --- a/pkg/exporter/rule.go +++ b/pkg/exporter/rule.go @@ -62,7 +62,7 @@ func (r *Rule) MatchesEvent(ev *kube.EnhancedEvent) bool { if val, ok := ev.InvolvedObject.Labels[k]; !ok { return false } else { - matches := matchString(val, v) + matches := matchString(v, val) if !matches { return false } From 28bf293b9fccf17649509d50b3953e743917dd5c Mon Sep 17 00:00:00 2001 From: Ivana Vilimonovic Date: Fri, 14 Aug 2020 18:31:31 -0400 Subject: [PATCH 2/2] add test for label regex --- pkg/exporter/rule_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/exporter/rule_test.go b/pkg/exporter/rule_test.go index 8c54c47..14c2f43 100644 --- a/pkg/exporter/rule_test.go +++ b/pkg/exporter/rule_test.go @@ -52,6 +52,21 @@ func TestBasicRegexRule(t *testing.T) { assert.False(t, r.MatchesEvent(ev3)) } +func TestLabelRegexRule(t *testing.T) { + ev := &kube.EnhancedEvent{} + ev.InvolvedObject.Labels = map[string]string{ + "version": "alpha-123", + } + + r := Rule{ + Labels: map[string]string{ + "version": "alpha", + }, + } + + assert.True(t, r.MatchesEvent(ev)) +} + func TestOneLabelMatchesRule(t *testing.T) { ev := &kube.EnhancedEvent{} ev.InvolvedObject.Labels = map[string]string{