Skip to content

Commit 4cd4454

Browse files
authored
Fix annotation/label filter setting (#3008)
* fix how options are loaded by removing special casing * oop * chlog * update to specific test * oop
1 parent dc38bf1 commit 4cd4454

File tree

5 files changed

+24
-39
lines changed

5 files changed

+24
-39
lines changed

.chloggen/fix-annot-again.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Fixes a bug that was preventing regexes from being loaded correctly. Now the filter provide is exactly what's used.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3007]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
This is technically a breaking change if a user relied on the previously broken regex functionality.
18+
This change will actually fix their regex to work where it didn't before. I expect that users would rather their
19+
regexes work than break silently.

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- group: e2e-multi-instrumentation
4141
setup: "add-multi-instrumentation-params prepare-e2e"
4242
- group: e2e-metadata-filters
43-
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=.*filter.out --labels=.*filter.out' prepare-e2e"
43+
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=.*filter.out --annotations-filter=config.*.gke.io.* --labels=.*filter.out' prepare-e2e"
4444
- group: e2e-automatic-rbac
4545
setup: "add-rbac-permissions-to-operator prepare-e2e"
4646
steps:

internal/config/options.go

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
package config
1616

1717
import (
18-
"regexp"
19-
"strings"
20-
2118
"github.com/go-logr/logr"
2219
"go.uber.org/zap/zapcore"
2320

@@ -211,24 +208,7 @@ func WithRBACPermissions(rAuto autoRBAC.Availability) Option {
211208

212209
func WithLabelFilters(labelFilters []string) Option {
213210
return func(o *options) {
214-
215-
filters := []string{}
216-
for _, pattern := range labelFilters {
217-
var result strings.Builder
218-
219-
for i, literal := range strings.Split(pattern, "*") {
220-
221-
// Replace * with .*
222-
if i > 0 {
223-
result.WriteString(".*")
224-
}
225-
// Quote any regular expression meta characters in the
226-
// literal text.
227-
result.WriteString(regexp.QuoteMeta(literal))
228-
}
229-
filters = append(filters, result.String())
230-
}
231-
o.labelsFilter = filters
211+
o.labelsFilter = append(o.labelsFilter, labelFilters...)
232212
}
233213
}
234214

@@ -237,23 +217,7 @@ func WithLabelFilters(labelFilters []string) Option {
237217
// * kubectl.kubernetes.io/last-applied-configuration.
238218
func WithAnnotationFilters(annotationFilters []string) Option {
239219
return func(o *options) {
240-
filters := o.annotationsFilter
241-
for _, pattern := range annotationFilters {
242-
var result strings.Builder
243-
244-
for i, literal := range strings.Split(pattern, "*") {
245-
246-
// Replace * with .*
247-
if i > 0 {
248-
result.WriteString(".*")
249-
}
250-
// Quote any regular expression meta characters in the
251-
// literal text.
252-
result.WriteString(regexp.QuoteMeta(literal))
253-
}
254-
filters = append(filters, result.String())
255-
}
256-
o.annotationsFilter = filters
220+
o.annotationsFilter = append(o.annotationsFilter, annotationFilters...)
257221
}
258222
}
259223

tests/e2e-metadata-filters/annotations/00-error.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: test-annotations-collector
55
annotations:
66
annotation.filter.out: "true"
7+
configmanagement.gke.io/token: "asdfasdf"
78
spec:
89
updateStrategy:
910
rollingUpdate:

tests/e2e-metadata-filters/annotations/00-install.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: test-annotations
55
annotations:
66
annotation.filter.out: "true"
7+
configmanagement.gke.io/token: "asdfasdf"
78
spec:
89
mode: daemonset
910
config: |

0 commit comments

Comments
 (0)