Skip to content

Commit

Permalink
Check labels annotations filter (#2923)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
yuriolisa authored May 6, 2024
1 parent 0e96e1f commit 9944af6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix-labels-annotations-filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: Fix of Labels and Annotations filter

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

# (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:
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 --labels=.*filter.out' prepare-e2e"
- group: e2e-automatic-rbac
setup: "add-rbac-permissions-to-operator prepare-e2e"
steps:
Expand Down
5 changes: 3 additions & 2 deletions internal/manifests/manifestutils/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
)

func IsFilteredSet(sourceSet string, filterSet []string) bool {
for _, pattern := range filterSet {
if match, _ := regexp.MatchString(pattern, sourceSet); match {
for _, basePattern := range filterSet {
pattern, _ := regexp.Compile(basePattern)
if match := pattern.MatchString(sourceSet); match {
return match
}
}
Expand Down
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"os"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -158,9 +159,8 @@ func main() {
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.")
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.")
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.")
pflag.StringArrayVar(&labelsFilter, "label", []string{}, "Labels to filter away from propagating onto deploys")
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")
pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.")
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")
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")
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.")
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")
pflag.Parse()
Expand Down Expand Up @@ -305,6 +305,23 @@ func main() {
setupLog.Info("Openshift CRDs are not installed, skipping adding to scheme.")
}

if cfg.AnnotationsFilter() != nil {
for _, basePattern := range cfg.AnnotationsFilter() {
_, compileErr := regexp.Compile(basePattern)
if compileErr != nil {
setupLog.Error(compileErr, "could not compile the regexp pattern for Annotations filter")
}
}
}
if cfg.LabelsFilter() != nil {
for _, basePattern := range cfg.LabelsFilter() {
_, compileErr := regexp.Compile(basePattern)
if compileErr != nil {
setupLog.Error(compileErr, "could not compile the regexp pattern for Labels filter")
}
}
}

err = addDependencies(ctx, mgr, cfg, v)
if err != nil {
setupLog.Error(err, "failed to add/run bootstrap dependencies to the controller manager")
Expand Down

0 comments on commit 9944af6

Please sign in to comment.