Skip to content

Commit 9944af6

Browse files
authored
Check labels annotations filter (#2923)
* Fixed Annotations/Labels filter Signed-off-by: Yuri Sa <[email protected]> * Fixed Annotations/Labels filter Signed-off-by: Yuri Sa <[email protected]> --------- Signed-off-by: Yuri Sa <[email protected]>
1 parent 0e96e1f commit 9944af6

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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: Fix of Labels and Annotations filter
9+
10+
# One or more tracking issues related to the change
11+
issues: [2770]
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:

.github/workflows/e2e.yaml

+1-1
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 --labels=.*filter.out' prepare-e2e"
4444
- group: e2e-automatic-rbac
4545
setup: "add-rbac-permissions-to-operator prepare-e2e"
4646
steps:

internal/manifests/manifestutils/labels.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import (
2525
)
2626

2727
func IsFilteredSet(sourceSet string, filterSet []string) bool {
28-
for _, pattern := range filterSet {
29-
if match, _ := regexp.MatchString(pattern, sourceSet); match {
28+
for _, basePattern := range filterSet {
29+
pattern, _ := regexp.Compile(basePattern)
30+
if match := pattern.MatchString(sourceSet); match {
3031
return match
3132
}
3233
}

main.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"flag"
2121
"fmt"
2222
"os"
23+
"regexp"
2324
"runtime"
2425
"strings"
2526
"time"
@@ -158,9 +159,8 @@ func main() {
158159
stringFlagOrEnv(&autoInstrumentationGo, "auto-instrumentation-go-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_GO", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-go-instrumentation/autoinstrumentation-go:%s", v.AutoInstrumentationGo), "The default OpenTelemetry Go instrumentation image. This image is used when no image is specified in the CustomResource.")
159160
stringFlagOrEnv(&autoInstrumentationApacheHttpd, "auto-instrumentation-apache-httpd-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_APACHE_HTTPD", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd:%s", v.AutoInstrumentationApacheHttpd), "The default OpenTelemetry Apache HTTPD instrumentation image. This image is used when no image is specified in the CustomResource.")
160161
stringFlagOrEnv(&autoInstrumentationNginx, "auto-instrumentation-nginx-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_NGINX", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd:%s", v.AutoInstrumentationNginx), "The default OpenTelemetry Nginx instrumentation image. This image is used when no image is specified in the CustomResource.")
161-
pflag.StringArrayVar(&labelsFilter, "label", []string{}, "Labels to filter away from propagating onto deploys")
162-
pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys. It should be a string array containing patterns, which are literal strings optionally containing a * wildcard character. Example: --annotations-filter=*filter.out will filter out annotations that looks like: annotation.filter.out: true")
163-
pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.")
162+
pflag.StringArrayVar(&labelsFilter, "label", []string{}, "Labels to filter away from propagating onto deploys. It should be a string array containing patterns, which are literal strings optionally containing a * wildcard character. Example: --labels-filter=.*filter.out will filter out labels that looks like: label.filter.out: true")
163+
pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys. It should be a string array containing patterns, which are literal strings optionally containing a * wildcard character. Example: --annotations-filter=.*filter.out will filter out annotations that looks like: annotation.filter.out: true")
164164
pflag.StringVar(&tlsOpt.minVersion, "tls-min-version", "VersionTLS12", "Minimum TLS version supported. Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants.")
165165
pflag.StringSliceVar(&tlsOpt.cipherSuites, "tls-cipher-suites", nil, "Comma-separated list of cipher suites for the server. Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants). If omitted, the default Go cipher suites will be used")
166166
pflag.Parse()
@@ -305,6 +305,23 @@ func main() {
305305
setupLog.Info("Openshift CRDs are not installed, skipping adding to scheme.")
306306
}
307307

308+
if cfg.AnnotationsFilter() != nil {
309+
for _, basePattern := range cfg.AnnotationsFilter() {
310+
_, compileErr := regexp.Compile(basePattern)
311+
if compileErr != nil {
312+
setupLog.Error(compileErr, "could not compile the regexp pattern for Annotations filter")
313+
}
314+
}
315+
}
316+
if cfg.LabelsFilter() != nil {
317+
for _, basePattern := range cfg.LabelsFilter() {
318+
_, compileErr := regexp.Compile(basePattern)
319+
if compileErr != nil {
320+
setupLog.Error(compileErr, "could not compile the regexp pattern for Labels filter")
321+
}
322+
}
323+
}
324+
308325
err = addDependencies(ctx, mgr, cfg, v)
309326
if err != nil {
310327
setupLog.Error(err, "failed to add/run bootstrap dependencies to the controller manager")

0 commit comments

Comments
 (0)