Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotation/label filter setting #3008

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading