Skip to content

Commit

Permalink
Fix annotation/label filter setting (#3008)
Browse files Browse the repository at this point in the history
* fix how options are loaded by removing special casing

* oop

* chlog

* update to specific test

* oop
  • Loading branch information
jaronoff97 authored Jun 5, 2024
1 parent dc38bf1 commit 4cd4454
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
19 changes: 19 additions & 0 deletions .chloggen/fix-annot-again.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes a bug that was preventing regexes from being loaded correctly. Now the filter provide is exactly what's used.

# One or more tracking issues related to the change
issues: [3007]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This is technically a breaking change if a user relied on the previously broken regex functionality.
This change will actually fix their regex to work where it didn't before. I expect that users would rather their
regexes work than break silently.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- group: e2e-multi-instrumentation
setup: "add-multi-instrumentation-params prepare-e2e"
- group: e2e-metadata-filters
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=.*filter.out --labels=.*filter.out' prepare-e2e"
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=.*filter.out --annotations-filter=config.*.gke.io.* --labels=.*filter.out' prepare-e2e"
- group: e2e-automatic-rbac
setup: "add-rbac-permissions-to-operator prepare-e2e"
steps:
Expand Down
40 changes: 2 additions & 38 deletions internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
package config

import (
"regexp"
"strings"

"github.com/go-logr/logr"
"go.uber.org/zap/zapcore"

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

func WithLabelFilters(labelFilters []string) Option {
return func(o *options) {

filters := []string{}
for _, pattern := range labelFilters {
var result strings.Builder

for i, literal := range strings.Split(pattern, "*") {

// Replace * with .*
if i > 0 {
result.WriteString(".*")
}
// Quote any regular expression meta characters in the
// literal text.
result.WriteString(regexp.QuoteMeta(literal))
}
filters = append(filters, result.String())
}
o.labelsFilter = filters
o.labelsFilter = append(o.labelsFilter, labelFilters...)
}
}

Expand All @@ -237,23 +217,7 @@ func WithLabelFilters(labelFilters []string) Option {
// * kubectl.kubernetes.io/last-applied-configuration.
func WithAnnotationFilters(annotationFilters []string) Option {
return func(o *options) {
filters := o.annotationsFilter
for _, pattern := range annotationFilters {
var result strings.Builder

for i, literal := range strings.Split(pattern, "*") {

// Replace * with .*
if i > 0 {
result.WriteString(".*")
}
// Quote any regular expression meta characters in the
// literal text.
result.WriteString(regexp.QuoteMeta(literal))
}
filters = append(filters, result.String())
}
o.annotationsFilter = filters
o.annotationsFilter = append(o.annotationsFilter, annotationFilters...)
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/e2e-metadata-filters/annotations/00-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: test-annotations-collector
annotations:
annotation.filter.out: "true"
configmanagement.gke.io/token: "asdfasdf"
spec:
updateStrategy:
rollingUpdate:
Expand Down
1 change: 1 addition & 0 deletions tests/e2e-metadata-filters/annotations/00-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: test-annotations
annotations:
annotation.filter.out: "true"
configmanagement.gke.io/token: "asdfasdf"
spec:
mode: daemonset
config: |
Expand Down

0 comments on commit 4cd4454

Please sign in to comment.