From 4f055221d15b90667974835980acf85304b907bd Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 29 Feb 2024 15:44:28 +0100 Subject: [PATCH 01/13] Created annotations filter Signed-off-by: Yuri Sa --- .chloggen/annotations-filter.yaml | 16 ++++++++ internal/config/main.go | 7 ++++ internal/config/options.go | 13 ++++-- internal/manifests/collector/daemonset.go | 5 ++- .../manifests/collector/daemonset_test.go | 2 +- internal/manifests/collector/deployment.go | 5 +-- .../manifests/collector/deployment_test.go | 2 +- .../collector/horizontalpodautoscaler.go | 2 +- .../collector/poddisruptionbudget.go | 2 +- internal/manifests/collector/statefulset.go | 4 +- .../manifests/collector/statefulset_test.go | 2 +- .../annotations.go | 26 +++++++----- .../annotations_test.go | 41 +++++++++++++++---- internal/manifests/manifestutils/labels.go | 8 ++-- .../manifests/opampbridge/deployment_test.go | 2 +- main.go | 6 ++- 16 files changed, 101 insertions(+), 42 deletions(-) create mode 100755 .chloggen/annotations-filter.yaml rename internal/manifests/{collector => manifestutils}/annotations.go (78%) rename internal/manifests/{collector => manifestutils}/annotations_test.go (82%) diff --git a/.chloggen/annotations-filter.yaml b/.chloggen/annotations-filter.yaml new file mode 100755 index 0000000000..e7f7a268a3 --- /dev/null +++ b/.chloggen/annotations-filter.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'enhancement' + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: operator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Created ability to filter out Annotations + +# One or more tracking issues related to the change +issues: [2627] + +# (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: diff --git a/internal/config/main.go b/internal/config/main.go index b336ed4bce..639233802b 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -55,6 +55,7 @@ type Config struct { autoInstrumentationJavaImage string openshiftRoutesAvailability openshift.RoutesAvailability labelsFilter []string + annotationsFilter []string } // New constructs a new configuration based on the given options. @@ -93,6 +94,7 @@ func New(opts ...Option) Config { autoInstrumentationApacheHttpdImage: o.autoInstrumentationApacheHttpdImage, autoInstrumentationNginxImage: o.autoInstrumentationNginxImage, labelsFilter: o.labelsFilter, + annotationsFilter: o.annotationsFilter, } } @@ -196,3 +198,8 @@ func (c *Config) AutoInstrumentationNginxImage() string { func (c *Config) LabelsFilter() []string { return c.labelsFilter } + +// AnnotationsFilter Returns the filters converted to regex strings used to filter out unwanted labels from propagations. +func (c *Config) AnnotationsFilter() []string { + return c.annotationsFilter +} diff --git a/internal/config/options.go b/internal/config/options.go index a87385d1f4..c44db7427a 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -50,6 +50,7 @@ type options struct { operatorOpAMPBridgeImage string openshiftRoutesAvailability openshift.RoutesAvailability labelsFilter []string + annotationsFilter []string } func WithAutoDetect(a autodetect.AutoDetect) Option { @@ -161,11 +162,11 @@ func WithOpenShiftRoutesAvailability(os openshift.RoutesAvailability) Option { } } -func WithLabelFilters(labelFilters []string) Option { +func WithSetFilters(setFilters []string, setType string) Option { return func(o *options) { filters := []string{} - for _, pattern := range labelFilters { + for _, pattern := range setFilters { var result strings.Builder for i, literal := range strings.Split(pattern, "*") { @@ -174,14 +175,18 @@ func WithLabelFilters(labelFilters []string) Option { 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()) } + switch filterType := setType; filterType { + case "labels": + o.labelsFilter = filters + case "annotations": + o.annotationsFilter = filters + } - o.labelsFilter = filters } } diff --git a/internal/manifests/collector/daemonset.go b/internal/manifests/collector/daemonset.go index c257be3397..c006dbd10a 100644 --- a/internal/manifests/collector/daemonset.go +++ b/internal/manifests/collector/daemonset.go @@ -29,11 +29,12 @@ func DaemonSet(params manifests.Params) (*appsv1.DaemonSet, error) { name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) - annotations, err := Annotations(params.OtelCol) + annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } - podAnnotations, err := PodAnnotations(params.OtelCol) + + podAnnotations, err := manifestutils.PodAnnotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } diff --git a/internal/manifests/collector/daemonset_test.go b/internal/manifests/collector/daemonset_test.go index 17a326967c..54165274c3 100644 --- a/internal/manifests/collector/daemonset_test.go +++ b/internal/manifests/collector/daemonset_test.go @@ -227,7 +227,7 @@ func TestDaemonsetFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) params := manifests.Params{ Config: cfg, diff --git a/internal/manifests/collector/deployment.go b/internal/manifests/collector/deployment.go index 58e80a2d7e..1cc105114b 100644 --- a/internal/manifests/collector/deployment.go +++ b/internal/manifests/collector/deployment.go @@ -28,13 +28,12 @@ import ( func Deployment(params manifests.Params) (*appsv1.Deployment, error) { name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) - - annotations, err := Annotations(params.OtelCol) + annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } - podAnnotations, err := PodAnnotations(params.OtelCol) + podAnnotations, err := manifestutils.PodAnnotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index 662ef1de62..333057b15a 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -309,7 +309,7 @@ func TestDeploymentFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) params := manifests.Params{ Config: cfg, diff --git a/internal/manifests/collector/horizontalpodautoscaler.go b/internal/manifests/collector/horizontalpodautoscaler.go index 758217bd99..28b0b3cc52 100644 --- a/internal/manifests/collector/horizontalpodautoscaler.go +++ b/internal/manifests/collector/horizontalpodautoscaler.go @@ -28,7 +28,7 @@ import ( func HorizontalPodAutoscaler(params manifests.Params) (*autoscalingv2.HorizontalPodAutoscaler, error) { name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) - annotations, err := Annotations(params.OtelCol) + annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } diff --git a/internal/manifests/collector/poddisruptionbudget.go b/internal/manifests/collector/poddisruptionbudget.go index 73fe774da0..619fc7a110 100644 --- a/internal/manifests/collector/poddisruptionbudget.go +++ b/internal/manifests/collector/poddisruptionbudget.go @@ -32,7 +32,7 @@ func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) - annotations, err := Annotations(params.OtelCol) + annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } diff --git a/internal/manifests/collector/statefulset.go b/internal/manifests/collector/statefulset.go index 7ac287a8da..bfb3a70964 100644 --- a/internal/manifests/collector/statefulset.go +++ b/internal/manifests/collector/statefulset.go @@ -29,12 +29,12 @@ func StatefulSet(params manifests.Params) (*appsv1.StatefulSet, error) { name := naming.Collector(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter()) - annotations, err := Annotations(params.OtelCol) + annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } - podAnnotations, err := PodAnnotations(params.OtelCol) + podAnnotations, err := manifestutils.PodAnnotations(params.OtelCol, params.Config.AnnotationsFilter()) if err != nil { return nil, err } diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index 0a9d822f29..6a7f103f0e 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -319,7 +319,7 @@ func TestStatefulSetFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) params := manifests.Params{ OtelCol: otelcol, diff --git a/internal/manifests/collector/annotations.go b/internal/manifests/manifestutils/annotations.go similarity index 78% rename from internal/manifests/collector/annotations.go rename to internal/manifests/manifestutils/annotations.go index 5f4c7c41be..b81494d409 100644 --- a/internal/manifests/collector/annotations.go +++ b/internal/manifests/manifestutils/annotations.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package collector +package manifestutils import ( "crypto/sha256" @@ -23,7 +23,7 @@ import ( ) // Annotations return the annotations for OpenTelemetryCollector pod. -func Annotations(instance v1beta1.OpenTelemetryCollector) (map[string]string, error) { +func Annotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations []string) (map[string]string, error) { // new map every time, so that we don't touch the instance's annotations annotations := map[string]string{} @@ -36,9 +36,11 @@ func Annotations(instance v1beta1.OpenTelemetryCollector) (map[string]string, er } // allow override of prometheus annotations - if nil != instance.Annotations { - for k, v := range instance.Annotations { - annotations[k] = v + if nil != instance.ObjectMeta.Annotations { + for k, v := range instance.ObjectMeta.Annotations { + if !isFilteredSet(k, filterAnnotations) { + annotations[k] = v + } } } @@ -54,16 +56,18 @@ func Annotations(instance v1beta1.OpenTelemetryCollector) (map[string]string, er } // PodAnnotations return the spec annotations for OpenTelemetryCollector pod. -func PodAnnotations(instance v1beta1.OpenTelemetryCollector) (map[string]string, error) { +func PodAnnotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations []string) (map[string]string, error) { // new map every time, so that we don't touch the instance's annotations podAnnotations := map[string]string{} - - // allow override of pod annotations - for k, v := range instance.Spec.PodAnnotations { - podAnnotations[k] = v + if nil != instance.Spec.PodAnnotations { + for k, v := range instance.Spec.PodAnnotations { + if !isFilteredSet(k, filterAnnotations) { + podAnnotations[k] = v + } + } } - annotations, err := Annotations(instance) + annotations, err := Annotations(instance, filterAnnotations) if err != nil { return nil, err } diff --git a/internal/manifests/collector/annotations_test.go b/internal/manifests/manifestutils/annotations_test.go similarity index 82% rename from internal/manifests/collector/annotations_test.go rename to internal/manifests/manifestutils/annotations_test.go index ec773f195a..8127e0969f 100644 --- a/internal/manifests/collector/annotations_test.go +++ b/internal/manifests/manifestutils/annotations_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package collector +package manifestutils import ( "testing" @@ -45,9 +45,9 @@ func TestDefaultAnnotations(t *testing.T) { } // test - annotations, err := Annotations(otelcol) + annotations, err := Annotations(otelcol, []string{}) require.NoError(t, err) - podAnnotations, err := PodAnnotations(otelcol) + podAnnotations, err := PodAnnotations(otelcol, []string{}) require.NoError(t, err) //verify @@ -79,9 +79,9 @@ func TestNonDefaultPodAnnotation(t *testing.T) { } // test - annotations, err := Annotations(otelcol) + annotations, err := Annotations(otelcol, []string{}) require.NoError(t, err) - podAnnotations, err := PodAnnotations(otelcol) + podAnnotations, err := PodAnnotations(otelcol, []string{}) require.NoError(t, err) //verify @@ -121,9 +121,9 @@ func TestUserAnnotations(t *testing.T) { } // test - annotations, err := Annotations(otelcol) + annotations, err := Annotations(otelcol, []string{}) require.NoError(t, err) - podAnnotations, err := PodAnnotations(otelcol) + podAnnotations, err := PodAnnotations(otelcol, []string{}) require.NoError(t, err) //verify @@ -148,9 +148,9 @@ func TestAnnotationsPropagateDown(t *testing.T) { } // test - annotations, err := Annotations(otelcol) + annotations, err := Annotations(otelcol, []string{}) require.NoError(t, err) - podAnnotations, err := PodAnnotations(otelcol) + podAnnotations, err := PodAnnotations(otelcol, []string{}) require.NoError(t, err) // verify @@ -159,3 +159,26 @@ func TestAnnotationsPropagateDown(t *testing.T) { assert.Equal(t, "mycomponent", podAnnotations["myapp"]) assert.Equal(t, "pod_annotation_value", podAnnotations["pod_annotation"]) } + +func TestAnnotationsFilter(t *testing.T) { + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{"test.bar.io": "foo", + "test.io/port": "1234", + "test.io/path": "/test", + }, + }, + Spec: v1beta1.OpenTelemetryCollectorSpec{ + Mode: "deployment", + }, + } + + // This requires the filter to be in regex match form and not the other simpler wildcard one. + annotations, err := Annotations(otelcol, []string{".*.bar.io"}) + + // verify + require.NoError(t, err) + assert.Len(t, annotations, 6) + assert.NotContains(t, annotations, "test.bar.io") + assert.Equal(t, "1234", annotations["test.io/port"]) +} diff --git a/internal/manifests/manifestutils/labels.go b/internal/manifests/manifestutils/labels.go index cfcf3d2430..2e097a3b1f 100644 --- a/internal/manifests/manifestutils/labels.go +++ b/internal/manifests/manifestutils/labels.go @@ -23,9 +23,9 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -func isFilteredLabel(label string, filterLabels []string) bool { - for _, pattern := range filterLabels { - match, _ := regexp.MatchString(pattern, label) +func isFilteredSet(sourceSet string, filterSet []string) bool { + for _, pattern := range filterSet { + match, _ := regexp.MatchString(pattern, sourceSet) return match } return false @@ -38,7 +38,7 @@ func Labels(instance metav1.ObjectMeta, name string, image string, component str base := map[string]string{} if nil != instance.Labels { for k, v := range instance.Labels { - if !isFilteredLabel(k, filterLabels) { + if !isFilteredSet(k, filterLabels) { base[k] = v } } diff --git a/internal/manifests/opampbridge/deployment_test.go b/internal/manifests/opampbridge/deployment_test.go index 4ec3f07de6..e0f341298a 100644 --- a/internal/manifests/opampbridge/deployment_test.go +++ b/internal/manifests/opampbridge/deployment_test.go @@ -237,7 +237,7 @@ func TestDeploymentFilterLabels(t *testing.T) { Spec: v1alpha1.OpAMPBridgeSpec{}, } - cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) params := manifests.Params{ Config: cfg, diff --git a/main.go b/main.go index 1711f4810e..3141ecac8d 100644 --- a/main.go +++ b/main.go @@ -120,6 +120,7 @@ func main() { autoInstrumentationNginx string autoInstrumentationGo string labelsFilter []string + annotationsFilter []string webhookPort int tlsOpt tlsConfig ) @@ -144,6 +145,7 @@ func main() { 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, "labels", []string{}, "Labels to filter away from propagating onto deploys") + pflag.StringArrayVar(&annotationsFilter, "annotations", []string{}, "Annotations to filter away from propagating onto deploys") pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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") @@ -170,6 +172,7 @@ func main() { "go-arch", runtime.GOARCH, "go-os", runtime.GOOS, "labels-filter", labelsFilter, + "annotations-filter", annotationsFilter, "enable-multi-instrumentation", enableMultiInstrumentation, "enable-apache-httpd-instrumentation", enableApacheHttpdInstrumentation, ) @@ -200,7 +203,8 @@ func main() { config.WithAutoInstrumentationApacheHttpdImage(autoInstrumentationApacheHttpd), config.WithAutoInstrumentationNginxImage(autoInstrumentationNginx), config.WithAutoDetect(ad), - config.WithLabelFilters(labelsFilter), + config.WithSetFilters(labelsFilter, "labels"), + config.WithSetFilters(annotationsFilter, "annotations"), ) err = cfg.AutoDetect() if err != nil { From 9d2c075f4c5892804d8e67ddd3a7fb1655d2c935 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 29 Feb 2024 15:54:09 +0100 Subject: [PATCH 02/13] Created annotations filters test Signed-off-by: Yuri Sa --- .../manifests/collector/daemonset_test.go | 31 +++++++++++++++++++ .../manifests/collector/deployment_test.go | 31 +++++++++++++++++++ .../manifests/collector/statefulset_test.go | 31 +++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/internal/manifests/collector/daemonset_test.go b/internal/manifests/collector/daemonset_test.go index 54165274c3..f3c375b6e9 100644 --- a/internal/manifests/collector/daemonset_test.go +++ b/internal/manifests/collector/daemonset_test.go @@ -244,6 +244,37 @@ func TestDaemonsetFilterLabels(t *testing.T) { } } +func TestDaemonsetFilterAnnotations(t *testing.T) { + excludedAnnotations := map[string]string{ + "foo": "1", + "app.foo.bar": "1", + } + + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + Annotations: excludedAnnotations, + }, + Spec: v1beta1.OpenTelemetryCollectorSpec{}, + } + + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + + params := manifests.Params{ + Config: cfg, + OtelCol: otelcol, + Log: logger, + } + + d, err := DaemonSet(params) + require.NoError(t, err) + + assert.Len(t, d.ObjectMeta.Annotations, 4) + for k := range excludedAnnotations { + assert.NotContains(t, d.ObjectMeta.Annotations, k) + } +} + func TestDaemonSetNodeSelector(t *testing.T) { // Test default otelcol1 := v1beta1.OpenTelemetryCollector{ diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index 333057b15a..92f8a2d46c 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -326,6 +326,37 @@ func TestDeploymentFilterLabels(t *testing.T) { } } +func TestDeploymentFilterAnnotations(t *testing.T) { + excludedAnnotations := map[string]string{ + "foo": "1", + "app.foo.bar": "1", + } + + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + Annotations: excludedAnnotations, + }, + Spec: v1beta1.OpenTelemetryCollectorSpec{}, + } + + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + + params := manifests.Params{ + Config: cfg, + OtelCol: otelcol, + Log: logger, + } + + d, err := Deployment(params) + require.NoError(t, err) + + assert.Len(t, d.ObjectMeta.Annotations, 4) + for k := range excludedAnnotations { + assert.NotContains(t, d.ObjectMeta.Annotations, k) + } +} + func TestDeploymentNodeSelector(t *testing.T) { // Test default otelcol1 := v1beta1.OpenTelemetryCollector{ diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index 6a7f103f0e..b0bf306aee 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -336,6 +336,37 @@ func TestStatefulSetFilterLabels(t *testing.T) { } } +func TestStatefulSetFilterAnnotations(t *testing.T) { + excludedAnnotations := map[string]string{ + "foo": "1", + "app.foo.bar": "1", + } + + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + Annotations: excludedAnnotations, + }, + Spec: v1beta1.OpenTelemetryCollectorSpec{}, + } + + cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + + params := manifests.Params{ + OtelCol: otelcol, + Config: cfg, + Log: logger, + } + + d, err := StatefulSet(params) + require.NoError(t, err) + + assert.Len(t, d.ObjectMeta.Annotations, 4) + for k := range excludedAnnotations { + assert.NotContains(t, d.ObjectMeta.Annotations, k) + } +} + func TestStatefulSetNodeSelector(t *testing.T) { // Test default otelcol1 := v1beta1.OpenTelemetryCollector{ From 73fcea52703ae4413d6d08bb485faa41b297cd13 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 29 Feb 2024 16:20:24 +0100 Subject: [PATCH 03/13] Adjusted linters Signed-off-by: Yuri Sa --- internal/manifests/collector/deployment_test.go | 2 +- internal/manifests/collector/statefulset_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index 92f8a2d46c..484c59d6c9 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -334,7 +334,7 @@ func TestDeploymentFilterAnnotations(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ - Name: "my-instance", + Name: "my-instance", Annotations: excludedAnnotations, }, Spec: v1beta1.OpenTelemetryCollectorSpec{}, diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index b0bf306aee..142bcb45ec 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -344,7 +344,7 @@ func TestStatefulSetFilterAnnotations(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ - Name: "my-instance", + Name: "my-instance", Annotations: excludedAnnotations, }, Spec: v1beta1.OpenTelemetryCollectorSpec{}, From acec6f937b77bee15e0895031731279751197fe0 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Fri, 1 Mar 2024 13:43:31 +0100 Subject: [PATCH 04/13] Added Annotations Filter for OpAMP and TA Signed-off-by: Yuri Sa --- controllers/builder_test.go | 3 + internal/config/options.go | 33 +++++-- .../manifests/collector/daemonset_test.go | 4 +- .../manifests/collector/deployment_test.go | 4 +- .../manifests/collector/statefulset_test.go | 4 +- .../manifests/manifestutils/annotations.go | 4 +- .../manifestutils/annotations_test.go | 6 +- internal/manifests/manifestutils/labels.go | 29 +++++- .../manifests/manifestutils/labels_test.go | 64 +++++++++++++ internal/manifests/opampbridge/annotations.go | 61 +++++++++++++ .../manifests/opampbridge/annotations_test.go | 61 +++++++++++++ internal/manifests/opampbridge/configmap.go | 6 +- internal/manifests/opampbridge/deployment.go | 9 +- .../manifests/opampbridge/deployment_test.go | 32 ++++++- .../manifests/targetallocator/annotations.go | 11 ++- .../targetallocator/annotations_test.go | 6 +- .../manifests/targetallocator/configmap.go | 2 +- .../manifests/targetallocator/deployment.go | 7 +- internal/manifests/targetallocator/labels.go | 41 --------- .../manifests/targetallocator/labels_test.go | 89 ------------------- .../targetallocator/poddisruptionbudget.go | 8 +- internal/manifests/targetallocator/service.go | 6 +- .../targetallocator/serviceaccount.go | 3 +- .../targetallocator/serviceaccount_test.go | 3 +- .../targetallocator/servicemonitor.go | 5 +- main.go | 4 +- 26 files changed, 327 insertions(+), 178 deletions(-) create mode 100644 internal/manifests/opampbridge/annotations.go create mode 100644 internal/manifests/opampbridge/annotations_test.go delete mode 100644 internal/manifests/targetallocator/labels.go delete mode 100644 internal/manifests/targetallocator/labels_test.go diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 4076ccd463..a8102e1906 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -930,6 +930,9 @@ func TestBuildAll_OpAMPBridge(t *testing.T) { "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", }, + Annotations: map[string]string{ + "opentelemetry-opampbridge-config/hash": "bd5cfc0df684966e25597a2847d5a3bae2c2b037d8bf10e7ea402ebe4d41c9f0", + }, }, Spec: appsv1.DeploymentSpec{ Replicas: &one, diff --git a/internal/config/options.go b/internal/config/options.go index c44db7427a..313c0b7317 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -162,11 +162,11 @@ func WithOpenShiftRoutesAvailability(os openshift.RoutesAvailability) Option { } } -func WithSetFilters(setFilters []string, setType string) Option { +func WithLabelFilters(labelFilters []string) Option { return func(o *options) { filters := []string{} - for _, pattern := range setFilters { + for _, pattern := range labelFilters { var result strings.Builder for i, literal := range strings.Split(pattern, "*") { @@ -181,12 +181,29 @@ func WithSetFilters(setFilters []string, setType string) Option { } filters = append(filters, result.String()) } - switch filterType := setType; filterType { - case "labels": - o.labelsFilter = filters - case "annotations": - o.annotationsFilter = filters - } + o.labelsFilter = filters + } +} + +func WithAnnotationFilters(annotationFilters []string) Option { + return func(o *options) { + + filters := []string{} + 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 } } diff --git a/internal/manifests/collector/daemonset_test.go b/internal/manifests/collector/daemonset_test.go index f3c375b6e9..778c3791f6 100644 --- a/internal/manifests/collector/daemonset_test.go +++ b/internal/manifests/collector/daemonset_test.go @@ -227,7 +227,7 @@ func TestDaemonsetFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) + cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ Config: cfg, @@ -258,7 +258,7 @@ func TestDaemonsetFilterAnnotations(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + cfg := config.New(config.WithAnnotationFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ Config: cfg, diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index 484c59d6c9..0523a214b6 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -309,7 +309,7 @@ func TestDeploymentFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) + cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ Config: cfg, @@ -340,7 +340,7 @@ func TestDeploymentFilterAnnotations(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + cfg := config.New(config.WithAnnotationFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ Config: cfg, diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index 142bcb45ec..5e0af9d110 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -319,7 +319,7 @@ func TestStatefulSetFilterLabels(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) + cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ OtelCol: otelcol, @@ -350,7 +350,7 @@ func TestStatefulSetFilterAnnotations(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "annotations")) + cfg := config.New(config.WithAnnotationFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ OtelCol: otelcol, diff --git a/internal/manifests/manifestutils/annotations.go b/internal/manifests/manifestutils/annotations.go index b81494d409..06f1baed81 100644 --- a/internal/manifests/manifestutils/annotations.go +++ b/internal/manifests/manifestutils/annotations.go @@ -38,7 +38,7 @@ func Annotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations []st // allow override of prometheus annotations if nil != instance.ObjectMeta.Annotations { for k, v := range instance.ObjectMeta.Annotations { - if !isFilteredSet(k, filterAnnotations) { + if !IsFilteredSet(k, filterAnnotations) { annotations[k] = v } } @@ -61,7 +61,7 @@ func PodAnnotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations [ podAnnotations := map[string]string{} if nil != instance.Spec.PodAnnotations { for k, v := range instance.Spec.PodAnnotations { - if !isFilteredSet(k, filterAnnotations) { + if !IsFilteredSet(k, filterAnnotations) { podAnnotations[k] = v } } diff --git a/internal/manifests/manifestutils/annotations_test.go b/internal/manifests/manifestutils/annotations_test.go index 8127e0969f..079b89878d 100644 --- a/internal/manifests/manifestutils/annotations_test.go +++ b/internal/manifests/manifestutils/annotations_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" @@ -163,7 +164,8 @@ func TestAnnotationsPropagateDown(t *testing.T) { func TestAnnotationsFilter(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{"test.bar.io": "foo", + Annotations: map[string]string{ + "test.bar.io": "foo", "test.io/port": "1234", "test.io/path": "/test", }, @@ -174,7 +176,7 @@ func TestAnnotationsFilter(t *testing.T) { } // This requires the filter to be in regex match form and not the other simpler wildcard one. - annotations, err := Annotations(otelcol, []string{".*.bar.io"}) + annotations, err := Annotations(otelcol, []string{".*\\.bar\\.io"}) // verify require.NoError(t, err) diff --git a/internal/manifests/manifestutils/labels.go b/internal/manifests/manifestutils/labels.go index 2e097a3b1f..9686a1705e 100644 --- a/internal/manifests/manifestutils/labels.go +++ b/internal/manifests/manifestutils/labels.go @@ -18,12 +18,13 @@ import ( "regexp" "strings" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - + "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/naming" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func isFilteredSet(sourceSet string, filterSet []string) bool { +func IsFilteredSet(sourceSet string, filterSet []string) bool { for _, pattern := range filterSet { match, _ := regexp.MatchString(pattern, sourceSet) return match @@ -38,7 +39,7 @@ func Labels(instance metav1.ObjectMeta, name string, image string, component str base := map[string]string{} if nil != instance.Labels { for k, v := range instance.Labels { - if !isFilteredSet(k, filterLabels) { + if !IsFilteredSet(k, filterLabels) { base[k] = v } } @@ -81,3 +82,23 @@ func SelectorLabels(instance metav1.ObjectMeta, component string) map[string]str "app.kubernetes.io/component": component, } } + +// Labels return the common labels to all TargetAllocator objects that are part of a managed OpenTelemetryCollector. +func TALabels(instance v1beta1.OpenTelemetryCollector, name string, component string) map[string]string { + return Labels(instance.ObjectMeta, name, instance.Spec.TargetAllocator.Image, component, nil) +} + +// SelectorLabels return the selector labels for Target Allocator Pods. +func TASelectorLabels(instance v1beta1.OpenTelemetryCollector, component string) map[string]string { + selectorLabels := SelectorLabels(instance.ObjectMeta, component) + + // TargetAllocator uses the name label as well for selection + // This is inconsistent with the Collector, but changing is a somewhat painful breaking change + // Don't override the app name if it already exists + if name, ok := instance.ObjectMeta.Labels["app.kubernetes.io/name"]; ok { + selectorLabels["app.kubernetes.io/name"] = name + } else { + selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name) + } + return selectorLabels +} diff --git a/internal/manifests/manifestutils/labels_test.go b/internal/manifests/manifestutils/labels_test.go index 4a0bd794de..33d71bcdd6 100644 --- a/internal/manifests/manifestutils/labels_test.go +++ b/internal/manifests/manifestutils/labels_test.go @@ -21,11 +21,16 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + + "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) const ( collectorName = "my-instance" collectorNamespace = "my-ns" + taname = "my-instance" + tanamespace = "my-ns" ) func TestLabelsCommonSet(t *testing.T) { @@ -168,3 +173,62 @@ func TestSelectorLabels(t *testing.T) { // verify assert.Equal(t, expected, result) } + +func TestLabelsTACommonSet(t *testing.T) { + // prepare + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: taname, + Namespace: tanamespace, + }, + } + + // test + labels := TALabels(otelcol, taname, "opentelemetry-targetallocator") + assert.Equal(t, "opentelemetry-operator", labels["app.kubernetes.io/managed-by"]) + assert.Equal(t, "my-ns.my-instance", labels["app.kubernetes.io/instance"]) + assert.Equal(t, "opentelemetry", labels["app.kubernetes.io/part-of"]) + assert.Equal(t, "opentelemetry-targetallocator", labels["app.kubernetes.io/component"]) + assert.Equal(t, "latest", labels["app.kubernetes.io/version"]) + assert.Equal(t, taname, labels["app.kubernetes.io/name"]) +} + +func TestLabelsTAPropagateDown(t *testing.T) { + // prepare + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "myapp": "mycomponent", + "app.kubernetes.io/name": "test", + }, + }, + } + + // test + labels := TALabels(otelcol, taname, "opentelemetry-targetallocator") + selectorLabels := TASelectorLabels(otelcol, "opentelemetry-targetallocator") + + // verify + assert.Len(t, labels, 7) + assert.Equal(t, "mycomponent", labels["myapp"]) + assert.Equal(t, "test", labels["app.kubernetes.io/name"]) + assert.Equal(t, "test", selectorLabels["app.kubernetes.io/name"]) +} + +func TestSelectorTALabels(t *testing.T) { + // prepare + otelcol := v1beta1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: taname, + Namespace: tanamespace, + }, + } + + // test + labels := TASelectorLabels(otelcol, "opentelemetry-targetallocator") + assert.Equal(t, "opentelemetry-operator", labels["app.kubernetes.io/managed-by"]) + assert.Equal(t, "my-ns.my-instance", labels["app.kubernetes.io/instance"]) + assert.Equal(t, "opentelemetry", labels["app.kubernetes.io/part-of"]) + assert.Equal(t, "opentelemetry-targetallocator", labels["app.kubernetes.io/component"]) + assert.Equal(t, naming.TargetAllocator(otelcol.Name), labels["app.kubernetes.io/name"]) +} diff --git a/internal/manifests/opampbridge/annotations.go b/internal/manifests/opampbridge/annotations.go new file mode 100644 index 0000000000..2f29b69eb4 --- /dev/null +++ b/internal/manifests/opampbridge/annotations.go @@ -0,0 +1,61 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package opampbridge + +import ( + "crypto/sha256" + "fmt" + + v1 "k8s.io/api/core/v1" + + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" +) + +const configMapHashAnnotationKey = "opentelemetry-opampbridge-config/hash" + +// Annotations returns the annotations for the OPAmpBridge Pod. +func Annotations(instance v1alpha1.OpAMPBridge, configMap *v1.ConfigMap, filterAnnotations []string) map[string]string { + // Make a copy of PodAnnotations to be safe + annotations := make(map[string]string, len(instance.Spec.PodAnnotations)) + for key, value := range instance.Spec.PodAnnotations { + annotations[key] = value + } + if nil != instance.ObjectMeta.Annotations { + for k, v := range instance.ObjectMeta.Annotations { + if !manifestutils.IsFilteredSet(k, filterAnnotations) { + annotations[k] = v + } + } + } + if configMap != nil { + cmHash := getConfigMapSHA(configMap) + if cmHash != "" { + annotations[configMapHashAnnotationKey] = getConfigMapSHA(configMap) + } + } + + return annotations +} + +// getConfigMapSHA returns the hash of the content of the OpAMPBridge ConfigMap. +func getConfigMapSHA(configMap *v1.ConfigMap) string { + configString, ok := configMap.Data[OpAMPBridgeFilename] + if !ok { + return "" + } + h := sha256.Sum256([]byte(configString)) + return fmt.Sprintf("%x", h) +} diff --git a/internal/manifests/opampbridge/annotations_test.go b/internal/manifests/opampbridge/annotations_test.go new file mode 100644 index 0000000000..cc4f030156 --- /dev/null +++ b/internal/manifests/opampbridge/annotations_test.go @@ -0,0 +1,61 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package opampbridge + +import ( + "crypto/sha256" + "fmt" + "testing" + + "github.com/go-logr/logr" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/config" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests" +) + +func TestConfigMapHash(t *testing.T) { + cfg := config.New() + excludedAnnotations := map[string]string{ + "foo": "1", + "app.foo.bar": "1", + "opampbridge": "true", + } + opampBridge := v1alpha1.OpAMPBridge{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + Annotations: excludedAnnotations, + }, + Spec: v1alpha1.OpAMPBridgeSpec{}, + } + params := manifests.Params{ + OpAMPBridge: opampBridge, + Config: cfg, + Log: logr.Discard(), + } + expectedConfigMap, err := ConfigMap(params) + require.NoError(t, err) + expectedConfig := expectedConfigMap.Data[OpAMPBridgeFilename] + require.NotEmpty(t, expectedConfig) + expectedHash := sha256.Sum256([]byte(expectedConfig)) + annotations := Annotations(opampBridge, expectedConfigMap, []string{".*\\.bar\\.io"}) + require.Contains(t, annotations, configMapHashAnnotationKey) + cmHash := annotations[configMapHashAnnotationKey] + assert.Equal(t, fmt.Sprintf("%x", expectedHash), cmHash) +} diff --git a/internal/manifests/opampbridge/configmap.go b/internal/manifests/opampbridge/configmap.go index 9f16ef5a6d..620b6c7c16 100644 --- a/internal/manifests/opampbridge/configmap.go +++ b/internal/manifests/opampbridge/configmap.go @@ -27,6 +27,10 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) +const ( + OpAMPBridgeFilename = "remoteconfiguration.yaml" +) + func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { name := naming.OpAMPBridgeConfigMap(params.OpAMPBridge.Name) version := strings.Split(params.OpAMPBridge.Spec.Image, ":") @@ -69,7 +73,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { Annotations: params.OpAMPBridge.Annotations, }, Data: map[string]string{ - "remoteconfiguration.yaml": string(configYAML), + OpAMPBridgeFilename: string(configYAML), }, }, nil } diff --git a/internal/manifests/opampbridge/deployment.go b/internal/manifests/opampbridge/deployment.go index 81c1e908a9..9b146c83eb 100644 --- a/internal/manifests/opampbridge/deployment.go +++ b/internal/manifests/opampbridge/deployment.go @@ -28,13 +28,18 @@ import ( func Deployment(params manifests.Params) *appsv1.Deployment { name := naming.OpAMPBridge(params.OpAMPBridge.Name) labels := manifestutils.Labels(params.OpAMPBridge.ObjectMeta, name, params.OpAMPBridge.Spec.Image, ComponentOpAMPBridge, params.Config.LabelsFilter()) - + configMap, err := ConfigMap(params) + if err != nil { + params.Log.Info("failed to construct OpAMPBridge ConfigMap for annotations") + configMap = nil + } + annotations := Annotations(params.OpAMPBridge, configMap, params.Config.AnnotationsFilter()) return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: params.OpAMPBridge.Namespace, Labels: labels, - Annotations: params.OpAMPBridge.Annotations, + Annotations: annotations, }, Spec: appsv1.DeploymentSpec{ Replicas: params.OpAMPBridge.Spec.Replicas, diff --git a/internal/manifests/opampbridge/deployment_test.go b/internal/manifests/opampbridge/deployment_test.go index e0f341298a..77af7843b0 100644 --- a/internal/manifests/opampbridge/deployment_test.go +++ b/internal/manifests/opampbridge/deployment_test.go @@ -237,7 +237,7 @@ func TestDeploymentFilterLabels(t *testing.T) { Spec: v1alpha1.OpAMPBridgeSpec{}, } - cfg := config.New(config.WithSetFilters([]string{"foo*", "app.*.bar"}, "labels")) + cfg := config.New(config.WithLabelFilters([]string{"foo*", "app.*.bar"})) params := manifests.Params{ Config: cfg, @@ -253,6 +253,36 @@ func TestDeploymentFilterLabels(t *testing.T) { } } +func TestDeploymentFilterAnnotations(t *testing.T) { + excludedAnnotations := map[string]string{ + "foo": "1", + "app.foo.bar": "1", + "opampbridge": "true", + } + + opampBridge := v1alpha1.OpAMPBridge{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-instance", + Annotations: excludedAnnotations, + }, + Spec: v1alpha1.OpAMPBridgeSpec{}, + } + + cfg := config.New(config.WithAnnotationFilters([]string{"foo*", "app.*.bar"})) + + params := manifests.Params{ + Config: cfg, + OpAMPBridge: opampBridge, + Log: logger, + } + + d := Deployment(params) + + assert.Len(t, d.ObjectMeta.Annotations, 2) + assert.NotContains(t, d.ObjectMeta.Annotations, "foo") + assert.NotContains(t, d.ObjectMeta.Annotations, "app.foo.bar") +} + func TestDeploymentNodeSelector(t *testing.T) { // Test default opampBridge1 := v1alpha1.OpAMPBridge{ diff --git a/internal/manifests/targetallocator/annotations.go b/internal/manifests/targetallocator/annotations.go index 8d98e55a81..5d8001ae55 100644 --- a/internal/manifests/targetallocator/annotations.go +++ b/internal/manifests/targetallocator/annotations.go @@ -21,18 +21,25 @@ import ( v1 "k8s.io/api/core/v1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" ) const configMapHashAnnotationKey = "opentelemetry-targetallocator-config/hash" // Annotations returns the annotations for the TargetAllocator Pod. -func Annotations(instance v1beta1.OpenTelemetryCollector, configMap *v1.ConfigMap) map[string]string { +func Annotations(instance v1beta1.OpenTelemetryCollector, configMap *v1.ConfigMap, filterAnnotations []string) map[string]string { // Make a copy of PodAnnotations to be safe annotations := make(map[string]string, len(instance.Spec.PodAnnotations)) for key, value := range instance.Spec.PodAnnotations { annotations[key] = value } - + if nil != instance.ObjectMeta.Annotations { + for k, v := range instance.ObjectMeta.Annotations { + if !manifestutils.IsFilteredSet(k, filterAnnotations) { + annotations[k] = v + } + } + } if configMap != nil { cmHash := getConfigMapSHA(configMap) if cmHash != "" { diff --git a/internal/manifests/targetallocator/annotations_test.go b/internal/manifests/targetallocator/annotations_test.go index bcdb127e52..d64aee4b9e 100644 --- a/internal/manifests/targetallocator/annotations_test.go +++ b/internal/manifests/targetallocator/annotations_test.go @@ -33,7 +33,7 @@ func TestPodAnnotations(t *testing.T) { instance.Spec.PodAnnotations = map[string]string{ "key": "value", } - annotations := Annotations(instance, nil) + annotations := Annotations(instance, nil, []string{".*\\.bar\\.io"}) assert.Subset(t, annotations, instance.Spec.PodAnnotations) } @@ -50,7 +50,7 @@ func TestConfigMapHash(t *testing.T) { expectedConfig := expectedConfigMap.Data[targetAllocatorFilename] require.NotEmpty(t, expectedConfig) expectedHash := sha256.Sum256([]byte(expectedConfig)) - annotations := Annotations(instance, expectedConfigMap) + annotations := Annotations(instance, expectedConfigMap, []string{".*\\.bar\\.io"}) require.Contains(t, annotations, configMapHashAnnotationKey) cmHash := annotations[configMapHashAnnotationKey] assert.Equal(t, fmt.Sprintf("%x", expectedHash), cmHash) @@ -59,6 +59,6 @@ func TestConfigMapHash(t *testing.T) { func TestInvalidConfigNoHash(t *testing.T) { instance := collectorInstance() instance.Spec.Config = v1beta1.Config{} - annotations := Annotations(instance, nil) + annotations := Annotations(instance, nil, []string{".*\\.bar\\.io"}) require.NotContains(t, annotations, configMapHashAnnotationKey) } diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index f4fe2be293..82c57b169f 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -33,7 +33,7 @@ const ( func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { name := naming.TAConfigMap(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) // TODO: https://github.com/open-telemetry/opentelemetry-operator/issues/2603 cfgStr, err := params.OtelCol.Spec.Config.Yaml() if err != nil { diff --git a/internal/manifests/targetallocator/deployment.go b/internal/manifests/targetallocator/deployment.go index c202c1443c..aa7748120b 100644 --- a/internal/manifests/targetallocator/deployment.go +++ b/internal/manifests/targetallocator/deployment.go @@ -20,20 +20,21 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // Deployment builds the deployment for the given instance. func Deployment(params manifests.Params) (*appsv1.Deployment, error) { name := naming.TargetAllocator(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) configMap, err := ConfigMap(params) if err != nil { params.Log.Info("failed to construct target allocator config map for annotations") configMap = nil } - annotations := Annotations(params.OtelCol, configMap) + annotations := Annotations(params.OtelCol, configMap, params.Config.AnnotationsFilter()) return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -44,7 +45,7 @@ func Deployment(params manifests.Params) (*appsv1.Deployment, error) { Spec: appsv1.DeploymentSpec{ Replicas: params.OtelCol.Spec.TargetAllocator.Replicas, Selector: &metav1.LabelSelector{ - MatchLabels: SelectorLabels(params.OtelCol), + MatchLabels: manifestutils.TASelectorLabels(params.OtelCol, ComponentOpenTelemetryTargetAllocator), }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/manifests/targetallocator/labels.go b/internal/manifests/targetallocator/labels.go deleted file mode 100644 index 899269128e..0000000000 --- a/internal/manifests/targetallocator/labels.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package targetallocator - -import ( - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" - "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" - "github.com/open-telemetry/opentelemetry-operator/internal/naming" -) - -// Labels return the common labels to all TargetAllocator objects that are part of a managed OpenTelemetryCollector. -func Labels(instance v1beta1.OpenTelemetryCollector, name string) map[string]string { - return manifestutils.Labels(instance.ObjectMeta, name, instance.Spec.TargetAllocator.Image, ComponentOpenTelemetryTargetAllocator, nil) -} - -// SelectorLabels return the selector labels for Target Allocator Pods. -func SelectorLabels(instance v1beta1.OpenTelemetryCollector) map[string]string { - selectorLabels := manifestutils.SelectorLabels(instance.ObjectMeta, ComponentOpenTelemetryTargetAllocator) - - // TargetAllocator uses the name label as well for selection - // This is inconsistent with the Collector, but changing is a somewhat painful breaking change - // Don't override the app name if it already exists - if name, ok := instance.ObjectMeta.Labels["app.kubernetes.io/name"]; ok { - selectorLabels["app.kubernetes.io/name"] = name - } else { - selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name) - } - return selectorLabels -} diff --git a/internal/manifests/targetallocator/labels_test.go b/internal/manifests/targetallocator/labels_test.go deleted file mode 100644 index 4304f97c25..0000000000 --- a/internal/manifests/targetallocator/labels_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package targetallocator - -import ( - "testing" - - "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" - "github.com/open-telemetry/opentelemetry-operator/internal/naming" -) - -const ( - name = "my-instance" - namespace = "my-ns" -) - -func TestLabelsCommonSet(t *testing.T) { - // prepare - otelcol := v1beta1.OpenTelemetryCollector{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - - // test - labels := Labels(otelcol, name) - assert.Equal(t, "opentelemetry-operator", labels["app.kubernetes.io/managed-by"]) - assert.Equal(t, "my-ns.my-instance", labels["app.kubernetes.io/instance"]) - assert.Equal(t, "opentelemetry", labels["app.kubernetes.io/part-of"]) - assert.Equal(t, "opentelemetry-targetallocator", labels["app.kubernetes.io/component"]) - assert.Equal(t, "latest", labels["app.kubernetes.io/version"]) - assert.Equal(t, name, labels["app.kubernetes.io/name"]) -} - -func TestLabelsPropagateDown(t *testing.T) { - // prepare - otelcol := v1beta1.OpenTelemetryCollector{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - "myapp": "mycomponent", - "app.kubernetes.io/name": "test", - }, - }, - } - - // test - labels := Labels(otelcol, name) - selectorLabels := SelectorLabels(otelcol) - - // verify - assert.Len(t, labels, 7) - assert.Equal(t, "mycomponent", labels["myapp"]) - assert.Equal(t, "test", labels["app.kubernetes.io/name"]) - assert.Equal(t, "test", selectorLabels["app.kubernetes.io/name"]) -} - -func TestSelectorLabels(t *testing.T) { - // prepare - otelcol := v1beta1.OpenTelemetryCollector{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - - // test - labels := SelectorLabels(otelcol) - assert.Equal(t, "opentelemetry-operator", labels["app.kubernetes.io/managed-by"]) - assert.Equal(t, "my-ns.my-instance", labels["app.kubernetes.io/instance"]) - assert.Equal(t, "opentelemetry", labels["app.kubernetes.io/part-of"]) - assert.Equal(t, "opentelemetry-targetallocator", labels["app.kubernetes.io/component"]) - assert.Equal(t, naming.TargetAllocator(otelcol.Name), labels["app.kubernetes.io/name"]) -} diff --git a/internal/manifests/targetallocator/poddisruptionbudget.go b/internal/manifests/targetallocator/poddisruptionbudget.go index f4e93869cc..bae141f4a9 100644 --- a/internal/manifests/targetallocator/poddisruptionbudget.go +++ b/internal/manifests/targetallocator/poddisruptionbudget.go @@ -19,6 +19,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" policyV1 "k8s.io/api/policy/v1" @@ -41,9 +42,8 @@ func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget } name := naming.TAPodDisruptionBudget(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) - - annotations := Annotations(params.OtelCol, nil) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) + annotations := Annotations(params.OtelCol, nil, params.Config.AnnotationsFilter()) objectMeta := metav1.ObjectMeta{ Name: name, @@ -58,7 +58,7 @@ func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget MinAvailable: params.OtelCol.Spec.TargetAllocator.PodDisruptionBudget.MinAvailable, MaxUnavailable: params.OtelCol.Spec.TargetAllocator.PodDisruptionBudget.MaxUnavailable, Selector: &metav1.LabelSelector{ - MatchLabels: SelectorLabels(params.OtelCol), + MatchLabels: manifestutils.TASelectorLabels(params.OtelCol, ComponentOpenTelemetryTargetAllocator), }, }, }, nil diff --git a/internal/manifests/targetallocator/service.go b/internal/manifests/targetallocator/service.go index 8238c00322..0f0444b6cc 100644 --- a/internal/manifests/targetallocator/service.go +++ b/internal/manifests/targetallocator/service.go @@ -20,14 +20,14 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) func Service(params manifests.Params) *corev1.Service { name := naming.TAService(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) - - selector := SelectorLabels(params.OtelCol) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) + selector := manifestutils.TASelectorLabels(params.OtelCol, ComponentOpenTelemetryTargetAllocator) return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/manifests/targetallocator/serviceaccount.go b/internal/manifests/targetallocator/serviceaccount.go index 6d29796c09..fb223dc20f 100644 --- a/internal/manifests/targetallocator/serviceaccount.go +++ b/internal/manifests/targetallocator/serviceaccount.go @@ -20,6 +20,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) @@ -39,7 +40,7 @@ func ServiceAccount(params manifests.Params) *corev1.ServiceAccount { } name := naming.TargetAllocatorServiceAccount(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) return &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/manifests/targetallocator/serviceaccount_test.go b/internal/manifests/targetallocator/serviceaccount_test.go index 4d469f2e9c..3acb49fd47 100644 --- a/internal/manifests/targetallocator/serviceaccount_test.go +++ b/internal/manifests/targetallocator/serviceaccount_test.go @@ -23,6 +23,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" ) func TestServiceAccountDefaultName(t *testing.T) { @@ -72,7 +73,7 @@ func TestServiceAccountDefault(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-targetallocator", Namespace: params.OtelCol.Namespace, - Labels: Labels(params.OtelCol, "my-instance-targetallocator"), + Labels: manifestutils.TALabels(params.OtelCol, "my-instance-targetallocator", ComponentOpenTelemetryTargetAllocator), Annotations: params.OtelCol.Annotations, }, } diff --git a/internal/manifests/targetallocator/servicemonitor.go b/internal/manifests/targetallocator/servicemonitor.go index 6f5c94c419..4c61e7eebb 100644 --- a/internal/manifests/targetallocator/servicemonitor.go +++ b/internal/manifests/targetallocator/servicemonitor.go @@ -19,13 +19,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // ServiceMonitor returns the service monitor for the given instance. func ServiceMonitor(params manifests.Params) *monitoringv1.ServiceMonitor { name := naming.TargetAllocator(params.OtelCol.Name) - labels := Labels(params.OtelCol, name) + labels := manifestutils.TALabels(params.OtelCol, name, ComponentOpenTelemetryTargetAllocator) return &monitoringv1.ServiceMonitor{ ObjectMeta: metav1.ObjectMeta{ @@ -44,7 +45,7 @@ func ServiceMonitor(params manifests.Params) *monitoringv1.ServiceMonitor { MatchNames: []string{params.OtelCol.Namespace}, }, Selector: metav1.LabelSelector{ - MatchLabels: SelectorLabels(params.OtelCol), + MatchLabels: manifestutils.TASelectorLabels(params.OtelCol, ComponentOpenTelemetryTargetAllocator), }, }, } diff --git a/main.go b/main.go index 3141ecac8d..7c450c122a 100644 --- a/main.go +++ b/main.go @@ -203,8 +203,8 @@ func main() { config.WithAutoInstrumentationApacheHttpdImage(autoInstrumentationApacheHttpd), config.WithAutoInstrumentationNginxImage(autoInstrumentationNginx), config.WithAutoDetect(ad), - config.WithSetFilters(labelsFilter, "labels"), - config.WithSetFilters(annotationsFilter, "annotations"), + config.WithLabelFilters(labelsFilter), + config.WithAnnotationFilters(annotationsFilter), ) err = cfg.AutoDetect() if err != nil { From 0c150f1ac7b979da8699cbc8e8c5b6bc461bc1a6 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 14:57:02 +0100 Subject: [PATCH 05/13] Added e2e tests for Labels and Annotations Signed-off-by: Yuri Sa --- .github/workflows/e2e.yaml | 3 +++ Makefile | 5 ++++ main.go | 2 +- .../annotations/00-error.yaml | 15 ++++++++++++ .../annotations/00-install.yaml | 24 +++++++++++++++++++ .../annotations/01-error.yaml | 15 ++++++++++++ .../annotations/01-patch.yaml | 6 +++++ .../annotations/chainsaw-test.yaml | 20 ++++++++++++++++ .../e2e-metadata-filters/labels/00-error.yaml | 15 ++++++++++++ .../labels/00-install.yaml | 24 +++++++++++++++++++ .../e2e-metadata-filters/labels/01-error.yaml | 15 ++++++++++++ .../e2e-metadata-filters/labels/01-patch.yaml | 6 +++++ .../labels/chainsaw-test.yaml | 20 ++++++++++++++++ 13 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 tests/e2e-metadata-filters/annotations/00-error.yaml create mode 100644 tests/e2e-metadata-filters/annotations/00-install.yaml create mode 100644 tests/e2e-metadata-filters/annotations/01-error.yaml create mode 100644 tests/e2e-metadata-filters/annotations/01-patch.yaml create mode 100755 tests/e2e-metadata-filters/annotations/chainsaw-test.yaml create mode 100644 tests/e2e-metadata-filters/labels/00-error.yaml create mode 100644 tests/e2e-metadata-filters/labels/00-install.yaml create mode 100644 tests/e2e-metadata-filters/labels/01-error.yaml create mode 100644 tests/e2e-metadata-filters/labels/01-patch.yaml create mode 100755 tests/e2e-metadata-filters/labels/chainsaw-test.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 1e6336c617..c8f074eeaf 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -32,11 +32,14 @@ jobs: - e2e-targetallocator - e2e-upgrade - e2e-multi-instrumentation + - e2e-metadata-filters include: - group: e2e-prometheuscr setup: "prepare-e2e-with-featuregates FEATUREGATES=+operator.observability.prometheus" - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" + - group: e2e-metadata-filters + setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --annotations=*filter.out" steps: - name: Check out code into the Go module directory diff --git a/Makefile b/Makefile index e59b2e571a..f8848d3d7a 100644 --- a/Makefile +++ b/Makefile @@ -240,6 +240,11 @@ e2e-prometheuscr: chainsaw e2e-targetallocator: chainsaw $(CHAINSAW) test --test-dir ./tests/e2e-targetallocator +# end-to-end-test for Annotations/Labels Filters +.PHONY: e2e-metadata-filters +e2e-metadata-filters: chainsaw + $(CHAINSAW) test --test-dir ./tests/metadata-filters + # end-to-end-test for testing upgrading .PHONY: e2e-upgrade e2e-upgrade: undeploy chainsaw diff --git a/main.go b/main.go index 7c450c122a..32e64f4653 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func main() { 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, "labels", []string{}, "Labels to filter away from propagating onto deploys") - pflag.StringArrayVar(&annotationsFilter, "annotations", []string{}, "Annotations to filter away from propagating onto deploys") + pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys") pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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") diff --git a/tests/e2e-metadata-filters/annotations/00-error.yaml b/tests/e2e-metadata-filters/annotations/00-error.yaml new file mode 100644 index 0000000000..be76e1f6d4 --- /dev/null +++ b/tests/e2e-metadata-filters/annotations/00-error.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: test-annotations-collector + annotations: + annotation.filter.out: "true" +spec: + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate +status: + numberMisscheduled: 0 + (desiredNumberScheduled == numberReady): true diff --git a/tests/e2e-metadata-filters/annotations/00-install.yaml b/tests/e2e-metadata-filters/annotations/00-install.yaml new file mode 100644 index 0000000000..66c0353334 --- /dev/null +++ b/tests/e2e-metadata-filters/annotations/00-install.yaml @@ -0,0 +1,24 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: test-annotations + annotations: + annotation.filter.out: "true" +spec: + mode: daemonset + config: | + receivers: + jaeger: + protocols: + grpc: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [jaeger] + processors: [] + exporters: [debug] diff --git a/tests/e2e-metadata-filters/annotations/01-error.yaml b/tests/e2e-metadata-filters/annotations/01-error.yaml new file mode 100644 index 0000000000..be76e1f6d4 --- /dev/null +++ b/tests/e2e-metadata-filters/annotations/01-error.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: test-annotations-collector + annotations: + annotation.filter.out: "true" +spec: + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate +status: + numberMisscheduled: 0 + (desiredNumberScheduled == numberReady): true diff --git a/tests/e2e-metadata-filters/annotations/01-patch.yaml b/tests/e2e-metadata-filters/annotations/01-patch.yaml new file mode 100644 index 0000000000..8b03dbe862 --- /dev/null +++ b/tests/e2e-metadata-filters/annotations/01-patch.yaml @@ -0,0 +1,6 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: test-annotations + annotations: + annotation.filter.out: "false" diff --git a/tests/e2e-metadata-filters/annotations/chainsaw-test.yaml b/tests/e2e-metadata-filters/annotations/chainsaw-test.yaml new file mode 100755 index 0000000000..32f6a88ec8 --- /dev/null +++ b/tests/e2e-metadata-filters/annotations/chainsaw-test.yaml @@ -0,0 +1,20 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: smoke-pod-annotations +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - error: + file: 00-error.yaml + - name: step-01 + try: + - patch: + file: 01-patch.yaml + - error: + file: 01-error.yaml diff --git a/tests/e2e-metadata-filters/labels/00-error.yaml b/tests/e2e-metadata-filters/labels/00-error.yaml new file mode 100644 index 0000000000..be76e1f6d4 --- /dev/null +++ b/tests/e2e-metadata-filters/labels/00-error.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: test-annotations-collector + annotations: + annotation.filter.out: "true" +spec: + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate +status: + numberMisscheduled: 0 + (desiredNumberScheduled == numberReady): true diff --git a/tests/e2e-metadata-filters/labels/00-install.yaml b/tests/e2e-metadata-filters/labels/00-install.yaml new file mode 100644 index 0000000000..f7728e0c2d --- /dev/null +++ b/tests/e2e-metadata-filters/labels/00-install.yaml @@ -0,0 +1,24 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: test-labels + labels: + annotation.filter.out: "true" +spec: + mode: daemonset + config: | + receivers: + jaeger: + protocols: + grpc: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [jaeger] + processors: [] + exporters: [debug] diff --git a/tests/e2e-metadata-filters/labels/01-error.yaml b/tests/e2e-metadata-filters/labels/01-error.yaml new file mode 100644 index 0000000000..be76e1f6d4 --- /dev/null +++ b/tests/e2e-metadata-filters/labels/01-error.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: test-annotations-collector + annotations: + annotation.filter.out: "true" +spec: + updateStrategy: + rollingUpdate: + maxSurge: 0 + maxUnavailable: 1 + type: RollingUpdate +status: + numberMisscheduled: 0 + (desiredNumberScheduled == numberReady): true diff --git a/tests/e2e-metadata-filters/labels/01-patch.yaml b/tests/e2e-metadata-filters/labels/01-patch.yaml new file mode 100644 index 0000000000..0b2206af16 --- /dev/null +++ b/tests/e2e-metadata-filters/labels/01-patch.yaml @@ -0,0 +1,6 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: test-labels + labels: + annotation.filter.out: "false" diff --git a/tests/e2e-metadata-filters/labels/chainsaw-test.yaml b/tests/e2e-metadata-filters/labels/chainsaw-test.yaml new file mode 100755 index 0000000000..32f6a88ec8 --- /dev/null +++ b/tests/e2e-metadata-filters/labels/chainsaw-test.yaml @@ -0,0 +1,20 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: smoke-pod-annotations +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - error: + file: 00-error.yaml + - name: step-01 + try: + - patch: + file: 01-patch.yaml + - error: + file: 01-error.yaml From 45287530eb5f7e91938ac2ce4f38f7e9f336b20a Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 17:50:03 +0100 Subject: [PATCH 06/13] Added e2e tests for Labels and Annotations Signed-off-by: Yuri Sa --- .github/workflows/e2e.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index c8f074eeaf..50bb1899f5 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,7 +39,7 @@ jobs: - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" - group: e2e-metadata-filters - setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --annotations=*filter.out" + setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --labels=*filter.out" steps: - name: Check out code into the Go module directory From 0ae1f1b8a8ca7aa49f448e8af9fea76d42f42498 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 18:02:24 +0100 Subject: [PATCH 07/13] Added e2e tests for Labels and Annotations Signed-off-by: Yuri Sa --- .github/workflows/e2e.yaml | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index c555cc9ede..e0102ab710 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,7 +39,7 @@ jobs: - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" - group: e2e-metadata-filters - setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --labels=*filter.out" + setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --labels-filter=*filter.out" steps: - name: Check out code into the Go module directory diff --git a/main.go b/main.go index 32e64f4653..ba27fccfe9 100644 --- a/main.go +++ b/main.go @@ -144,7 +144,7 @@ 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, "labels", []string{}, "Labels to filter away from propagating onto deploys") + pflag.StringArrayVar(&labelsFilter, "labels-filter", []string{}, "Labels to filter away from propagating onto deploys") pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys") pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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.") From 11908cf0d1e10e3ecd51a0c09975bed7c5952ba3 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 18:14:51 +0100 Subject: [PATCH 08/13] Added e2e tests for Labels and Annotations Signed-off-by: Yuri Sa --- .github/workflows/e2e.yaml | 2 +- config/manager/kustomization.yaml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index e0102ab710..9dc6a5482f 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,7 +39,7 @@ jobs: - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" - group: e2e-metadata-filters - setup: "add-operator-arg OPERATOR_ARG=--annotations-filter=*filter.out --labels-filter=*filter.out" + setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=*filter.out --labels-filter=*filter.out' prepare-e2e" steps: - name: Check out code into the Go module directory diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84cb..3ca6330ea6 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,9 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +patches: +- patch: '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--annotations-filter=*filter.out + --labels-filter=*filter.out"}]' + target: + kind: Deployment From 9a68cf62b8a987ad6c45ddcee23aa4efe4ed80d2 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 18:23:49 +0100 Subject: [PATCH 09/13] Fixed tests Signed-off-by: Yuri Sa --- .github/workflows/e2e.yaml | 2 +- Makefile | 2 +- main.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 9dc6a5482f..2f3dbf260e 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,7 +39,7 @@ jobs: - group: e2e-multi-instrumentation setup: "add-operator-arg OPERATOR_ARG=--enable-multi-instrumentation prepare-e2e" - group: e2e-metadata-filters - setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=*filter.out --labels-filter=*filter.out' prepare-e2e" + setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=*filter.out --labels=*filter.out' prepare-e2e" steps: - name: Check out code into the Go module directory diff --git a/Makefile b/Makefile index f8848d3d7a..5d10247f24 100644 --- a/Makefile +++ b/Makefile @@ -243,7 +243,7 @@ e2e-targetallocator: chainsaw # end-to-end-test for Annotations/Labels Filters .PHONY: e2e-metadata-filters e2e-metadata-filters: chainsaw - $(CHAINSAW) test --test-dir ./tests/metadata-filters + $(CHAINSAW) test --test-dir ./tests/e2e-metadata-filters # end-to-end-test for testing upgrading .PHONY: e2e-upgrade diff --git a/main.go b/main.go index ba27fccfe9..32e64f4653 100644 --- a/main.go +++ b/main.go @@ -144,7 +144,7 @@ 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, "labels-filter", []string{}, "Labels to filter away from propagating onto deploys") + pflag.StringArrayVar(&labelsFilter, "labels", []string{}, "Labels to filter away from propagating onto deploys") pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys") pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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.") From 3e907256132c5cff484c36f9b17c207d954349f1 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Mon, 4 Mar 2024 18:35:23 +0100 Subject: [PATCH 10/13] Reverting kustomization Signed-off-by: Yuri Sa --- config/manager/kustomization.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 3ca6330ea6..2e6cc79764 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,9 +1,2 @@ resources: -- manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -patches: -- patch: '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--annotations-filter=*filter.out - --labels-filter=*filter.out"}]' - target: - kind: Deployment +- manager.yaml \ No newline at end of file From cabf5b5561eea3a882d2848762000432c102f313 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 5 Mar 2024 14:44:05 +0100 Subject: [PATCH 11/13] Reverting kustomization Signed-off-by: Yuri Sa --- config/manager/kustomization.yaml | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 2e6cc79764..5c5f0b84cb 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,2 @@ resources: -- manager.yaml \ No newline at end of file +- manager.yaml diff --git a/main.go b/main.go index 32e64f4653..057f4216fe 100644 --- a/main.go +++ b/main.go @@ -144,7 +144,7 @@ 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, "labels", []string{}, "Labels to filter away from propagating onto deploys") + 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") pflag.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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.") From b256cdbb226da9cddcaab48077f08a5717e2af36 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 7 Mar 2024 10:34:23 +0100 Subject: [PATCH 12/13] Improved annotations Signed-off-by: Yuri Sa --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 057f4216fe..6b2b0be9c1 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func main() { 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") + pflag.StringArrayVar(&annotationsFilter, "annotations-filter", []string{}, "Annotations to filter away from propagating onto deploys. It should be a string array that contains any match of the regular expression pattern. 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.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") From 7d21e6be7bdcf77c374115b5437fb5c23c53600c Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 7 Mar 2024 11:21:33 +0100 Subject: [PATCH 13/13] Changed description Signed-off-by: Yuri Sa --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 6b2b0be9c1..6385b449ba 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func main() { 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 that contains any match of the regular expression pattern. Example: --annotations-filter=*filter.out will filter out annotations that looks like: annotation.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.IntVar(&webhookPort, "webhook-port", 9443, "The port the webhook endpoint binds to.") 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")