From b07ad6b14587421dc3747df586e26aa20b8a17f9 Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Mon, 23 Dec 2024 19:49:52 +0100 Subject: [PATCH 1/6] feat: expose namespace selector labels conf --- ...t-add-prometheuscr-namespaceselectors.yaml | 17 ++++ README.md | 7 ++ apis/v1beta1/targetallocator_types.go | 24 +++++ controllers/builder_test.go | 63 +++++++++--- .../manifests/targetallocator/configmap.go | 8 ++ .../targetallocator/configmap_test.go | 99 +++++++++++++++++++ 6 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 .chloggen/feat-add-prometheuscr-namespaceselectors.yaml diff --git a/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml b/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml new file mode 100644 index 0000000000..d4bbbe20af --- /dev/null +++ b/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml @@ -0,0 +1,17 @@ +# 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. collector, target allocator, auto-instrumentation, opamp, github action) +component: 'operator' + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add Prometheus CR namespace selectors" + +# One or more tracking issues related to the change +issues: + - 3086 + +# (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/README.md b/README.md index 71619cdc74..bb31070c3d 100644 --- a/README.md +++ b/README.md @@ -709,8 +709,15 @@ spec: serviceAccount: everything-prometheus-operator-needs prometheusCR: enabled: true + scrapeInterval: 30s serviceMonitorSelector: {} + serviceMonitorNamespaceSelector: {} podMonitorSelector: {} + podMonitorNamespaceSelector: {} + scrapeConfigSelector: {} + scrapeConfigNamespaceSelector: {} + probeSelector: {} + probeNamespaceSelector: {} config: receivers: prometheus: diff --git a/apis/v1beta1/targetallocator_types.go b/apis/v1beta1/targetallocator_types.go index ca9bc9aa0c..8a398c9c63 100644 --- a/apis/v1beta1/targetallocator_types.go +++ b/apis/v1beta1/targetallocator_types.go @@ -36,24 +36,48 @@ type TargetAllocatorPrometheusCR struct { // label selector matches no objects. // +optional PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"` + // Namespaces to be selected to look for PodMonitors for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"` // ServiceMonitors to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"` + // Namespaces to be selected to look for ServiceMonitors for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"` // ScrapeConfigs to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"` + // Namespaces to be selected to look for ScrapeConfigs for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"` // Probes to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"` + // Namespaces to be selected to look for Probes for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"` } type ( diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 053bf6966a..2dadd3fe52 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -1512,9 +1512,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -1548,7 +1553,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -1680,7 +1685,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -1971,9 +1976,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -2007,7 +2017,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -2139,7 +2149,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -2475,9 +2485,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -2511,7 +2526,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: corev1.PodSpec{ @@ -2669,7 +2684,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3544,9 +3559,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -3580,7 +3600,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: corev1.PodSpec{ @@ -3712,7 +3732,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3819,9 +3839,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -3855,7 +3880,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: corev1.PodSpec{ @@ -3987,7 +4012,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4144,9 +4169,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -4180,7 +4210,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -4312,7 +4342,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4443,9 +4473,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -4479,7 +4514,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: corev1.PodSpec{ @@ -4637,7 +4672,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index 27eb606b47..ae2e29a57b 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -107,12 +107,20 @@ func ConfigMap(params Params) (*corev1.ConfigMap, error) { prometheusCRConfig["service_monitor_selector"] = taSpec.PrometheusCR.ServiceMonitorSelector + prometheusCRConfig["service_monitor_namespace_selector"] = taSpec.PrometheusCR.ServiceMonitorNamespaceSelector + prometheusCRConfig["pod_monitor_selector"] = taSpec.PrometheusCR.PodMonitorSelector + prometheusCRConfig["pod_monitor_namespace_selector"] = taSpec.PrometheusCR.PodMonitorNamespaceSelector + prometheusCRConfig["scrape_config_selector"] = taSpec.PrometheusCR.ScrapeConfigSelector + prometheusCRConfig["scrape_config_namespace_selector"] = taSpec.PrometheusCR.ScrapeConfigNamespaceSelector + prometheusCRConfig["probe_selector"] = taSpec.PrometheusCR.ProbeSelector + prometheusCRConfig["probe_namespace_selector"] = taSpec.PrometheusCR.ProbeNamespaceSelector + taConfig["prometheus_cr"] = prometheusCRConfig } diff --git a/internal/manifests/targetallocator/configmap_test.go b/internal/manifests/targetallocator/configmap_test.go index 7cd6318b25..11a9a7f61c 100644 --- a/internal/manifests/targetallocator/configmap_test.go +++ b/internal/manifests/targetallocator/configmap_test.go @@ -167,18 +167,22 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: matchlabels: release: my-instance matchexpressions: [] + probe_namespace_selector: null probe_selector: matchlabels: release: my-instance matchexpressions: [] + scrape_config_namespace_selector: null scrape_config_selector: matchlabels: release: my-instance matchexpressions: [] + service_monitor_namespace_selector: null service_monitor_selector: matchlabels: release: my-instance @@ -217,6 +221,89 @@ prometheus_cr: assert.Equal(t, expectedLabels, actual.Labels) assert.Equal(t, expectedData, actual.Data) + }) + t.Run("should return expected target allocator config map with namespace label selectors", func(t *testing.T) { + expectedData := map[string]string{ + targetAllocatorFilename: `allocation_strategy: consistent-hashing +collector_selector: + matchlabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: default.my-instance + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + matchexpressions: [] +config: + global: + scrape_interval: 30s + scrape_protocols: + - PrometheusProto + - OpenMetricsText1.0.0 + - OpenMetricsText0.0.1 + - PrometheusText0.0.4 + scrape_configs: + - job_name: otel-collector + scrape_interval: 10s + static_configs: + - targets: + - 0.0.0.0:8888 + - 0.0.0.0:9999 +filter_strategy: relabel-config +prometheus_cr: + enabled: true + pod_monitor_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + pod_monitor_selector: null + probe_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + probe_selector: null + scrape_config_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + scrape_config_selector: null + service_monitor_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + service_monitor_selector: null +`, + } + targetAllocator = targetAllocatorInstance() + targetAllocator.Spec.PrometheusCR.Enabled = true + targetAllocator.Spec.PrometheusCR.PodMonitorNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }, + } + targetAllocator.Spec.PrometheusCR.ServiceMonitorNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.PrometheusCR.ScrapeConfigNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.PrometheusCR.ProbeNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.GlobalConfig = v1beta1.AnyConfig{ + Object: map[string]interface{}{ + "scrape_interval": "30s", + "scrape_protocols": []string{"PrometheusProto", "OpenMetricsText1.0.0", "OpenMetricsText0.0.1", "PrometheusText0.0.4"}, + }, + } + params.TargetAllocator = targetAllocator + actual, err := ConfigMap(params) + assert.NoError(t, err) + assert.Equal(t, "my-instance-targetallocator", actual.Name) + assert.Equal(t, expectedLabels, actual.Labels) + assert.Equal(t, expectedData, actual.Data) + }) t.Run("should return expected target allocator config map with scrape interval set", func(t *testing.T) { expectedData := map[string]string{ @@ -239,10 +326,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } @@ -302,10 +393,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } @@ -361,10 +456,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } From 7d1f53f3f80985930e0d03b7828029d4eb46f667 Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Sat, 28 Dec 2024 02:40:53 +0100 Subject: [PATCH 2/6] fix: set defaults + remove extra spacing --- apis/v1beta1/targetallocator_types.go | 4 ++++ internal/manifests/targetallocator/configmap.go | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/apis/v1beta1/targetallocator_types.go b/apis/v1beta1/targetallocator_types.go index 8a398c9c63..911ea4c10a 100644 --- a/apis/v1beta1/targetallocator_types.go +++ b/apis/v1beta1/targetallocator_types.go @@ -41,6 +41,7 @@ type TargetAllocatorPrometheusCR struct { // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional + // +kubebuilder:default:={} PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"` // ServiceMonitors to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and @@ -53,6 +54,7 @@ type TargetAllocatorPrometheusCR struct { // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional + // +kubebuilder:default:={} ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"` // ScrapeConfigs to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and @@ -65,6 +67,7 @@ type TargetAllocatorPrometheusCR struct { // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional + // +kubebuilder:default:={} ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"` // Probes to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and @@ -77,6 +80,7 @@ type TargetAllocatorPrometheusCR struct { // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional + // +kubebuilder:default:={} ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"` } diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index ae2e29a57b..ea91fe1fc3 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -104,23 +104,14 @@ func ConfigMap(params Params) (*corev1.ConfigMap, error) { if taSpec.PrometheusCR.ScrapeInterval.Size() > 0 { prometheusCRConfig["scrape_interval"] = taSpec.PrometheusCR.ScrapeInterval.Duration } - prometheusCRConfig["service_monitor_selector"] = taSpec.PrometheusCR.ServiceMonitorSelector - prometheusCRConfig["service_monitor_namespace_selector"] = taSpec.PrometheusCR.ServiceMonitorNamespaceSelector - prometheusCRConfig["pod_monitor_selector"] = taSpec.PrometheusCR.PodMonitorSelector - prometheusCRConfig["pod_monitor_namespace_selector"] = taSpec.PrometheusCR.PodMonitorNamespaceSelector - prometheusCRConfig["scrape_config_selector"] = taSpec.PrometheusCR.ScrapeConfigSelector - prometheusCRConfig["scrape_config_namespace_selector"] = taSpec.PrometheusCR.ScrapeConfigNamespaceSelector - prometheusCRConfig["probe_selector"] = taSpec.PrometheusCR.ProbeSelector - prometheusCRConfig["probe_namespace_selector"] = taSpec.PrometheusCR.ProbeNamespaceSelector - taConfig["prometheus_cr"] = prometheusCRConfig } From db9780867b4be10f0ea140fcda5df6a70f421ae4 Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Sat, 28 Dec 2024 12:46:43 +0100 Subject: [PATCH 3/6] fix tests --- apis/v1beta1/zz_generated.deepcopy.go | 20 + ...emetry-operator.clusterserviceversion.yaml | 2 +- ...ntelemetry.io_opentelemetrycollectors.yaml | 108 +++++ ...emetry-operator.clusterserviceversion.yaml | 2 +- ...ntelemetry.io_opentelemetrycollectors.yaml | 108 +++++ ...ntelemetry.io_opentelemetrycollectors.yaml | 108 +++++ .../opentelemetry.io_targetallocators.yaml | 108 +++++ config/manager/kustomization.yaml | 6 +- controllers/builder_test.go | 7 - docs/api.md | 388 ++++++++++++++++++ 10 files changed, 847 insertions(+), 10 deletions(-) diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 8d2402a809..33e4acfa52 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -782,21 +782,41 @@ func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPromethe *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.PodMonitorNamespaceSelector != nil { + in, out := &in.PodMonitorNamespaceSelector, &out.PodMonitorNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ServiceMonitorSelector != nil { in, out := &in.ServiceMonitorSelector, &out.ServiceMonitorSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ServiceMonitorNamespaceSelector != nil { + in, out := &in.ServiceMonitorNamespaceSelector, &out.ServiceMonitorNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ScrapeConfigSelector != nil { in, out := &in.ScrapeConfigSelector, &out.ScrapeConfigSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ScrapeConfigNamespaceSelector != nil { + in, out := &in.ScrapeConfigNamespaceSelector, &out.ScrapeConfigNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ProbeSelector != nil { in, out := &in.ProbeSelector, &out.ProbeSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ProbeNamespaceSelector != nil { + in, out := &in.ProbeNamespaceSelector, &out.ProbeNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorPrometheusCR. diff --git a/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml index 3086cedb57..02df421157 100644 --- a/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-12-19T16:56:26Z" + createdAt: "2024-12-28T16:14:39Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 diff --git a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 54034ecd2e..6ea9b99317 100644 --- a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7883,6 +7883,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7909,6 +7936,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7935,6 +7989,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7965,6 +8046,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml index ed82b5b7eb..bcc99001b3 100644 --- a/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-12-19T16:56:38Z" + createdAt: "2024-12-28T16:14:44Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 diff --git a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 54034ecd2e..6ea9b99317 100644 --- a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7883,6 +7883,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7909,6 +7936,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7935,6 +7989,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7965,6 +8046,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 9142b75a58..e82f0a31ce 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -7869,6 +7869,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7895,6 +7922,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7921,6 +7975,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7951,6 +8032,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/crd/bases/opentelemetry.io_targetallocators.yaml b/config/crd/bases/opentelemetry.io_targetallocators.yaml index 30e5c5c721..ce63cd0702 100644 --- a/config/crd/bases/opentelemetry.io_targetallocators.yaml +++ b/config/crd/bases/opentelemetry.io_targetallocators.yaml @@ -2243,6 +2243,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -2269,6 +2296,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -2295,6 +2349,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -2325,6 +2406,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 372a75ae43..40c0846afa 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,3 +1,7 @@ resources: - manager.yaml - +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 2dadd3fe52..1ee6f4e429 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -1518,7 +1518,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -1982,7 +1981,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -2491,7 +2489,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -3565,7 +3562,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -3845,7 +3841,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -4175,7 +4170,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, @@ -4479,7 +4473,6 @@ prometheus_cr: probe_selector: null scrape_config_namespace_selector: null scrape_config_selector: null - scrape_interval: 30s service_monitor_namespace_selector: null service_monitor_selector: null `, diff --git a/docs/api.md b/docs/api.md index e0c219d54d..65e63306e4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -48086,6 +48086,18 @@ All CR instances which the ServiceAccount has access to will be retrieved. This Enabled indicates whether to use a PrometheusOperator custom resources as targets or not.
false + + podMonitorNamespaceSelector + object + + Namespaces to be selected to look for PodMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false podMonitorSelector object @@ -48096,6 +48108,18 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.
false + + probeNamespaceSelector + object + + Namespaces to be selected to look for Probes for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false probeSelector object @@ -48106,6 +48130,18 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.
false + + scrapeConfigNamespaceSelector + object + + Namespaces to be selected to look for ScrapeConfigs for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false scrapeConfigSelector object @@ -48129,6 +48165,18 @@ Default: "30s"
Default: 30s
false + + serviceMonitorNamespaceSelector + object + + Namespaces to be selected to look for ServiceMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false serviceMonitorSelector object @@ -48143,6 +48191,91 @@ label selector matches no objects.
+### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for PodMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrpodmonitornamespaceselector) + + + +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + ### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorSelector [↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) @@ -48187,6 +48320,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.probeNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for Probes for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.probeNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrprobenamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. @@ -48272,6 +48490,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.scrapeConfigNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for ScrapeConfigs for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.scrapeConfigNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrscrapeconfignamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. @@ -48357,6 +48660,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.serviceMonitorNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for ServiceMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.serviceMonitorNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrservicemonitornamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. From 5c72fa92d1dd7b7ddcb3897db5e614f67db89a9b Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Thu, 2 Jan 2025 21:10:29 +0100 Subject: [PATCH 4/6] feat: add e2e --- .../03-assert.yaml | 28 +++ .../03-install.yaml | 164 ++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml new file mode 100644 index 0000000000..79c1f8876c --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: prometheus-cr-collector +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus-cr-targetallocator +status: + observedGeneration: 1 + readyReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +data: + targetallocator.yaml: + ( contains(@, join(':', ['service_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['pod_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['probe_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['scrape_config_namespace_selector', '{}'])) ): true +kind: ConfigMap +metadata: + name: prometheus-cr-v1beta1-targetallocator +--- \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml new file mode 100644 index 0000000000..3eeb8fc9e0 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml @@ -0,0 +1,164 @@ +apiVersion: v1 +automountServiceAccountToken: true +kind: ServiceAccount +metadata: + name: ta +--- +apiVersion: v1 +automountServiceAccountToken: true +kind: ServiceAccount +metadata: + name: collector +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: targetallocator-prometheuscr +rules: +- apiGroups: + - "" + resources: + - pods + - nodes + - services + - endpoints + - configmaps + - secrets + - namespaces + verbs: + - get + - watch + - list +- apiGroups: + - apps + resources: + - statefulsets + - services + - endpoints + verbs: + - get + - watch + - list +- apiGroups: + - discovery.k8s.io + resources: + - endpointslices + verbs: + - get + - watch + - list +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - watch + - list +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + - podmonitors + - scrapeconfigs + - probes + verbs: + - get + - watch + - list +- nonResourceURLs: + - /metrics + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: collector-prometheuscr +rules: +- apiGroups: + - "" + resources: + - pods + - nodes + - nodes/metrics + - services + - endpoints + - namespaces + verbs: + - get + - watch + - list +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - watch + - list +- nonResourceURLs: + - /metrics + - /metrics/cadvisor + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: (join('-', ['ta', $namespace])) +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: targetallocator-prometheuscr +subjects: +- kind: ServiceAccount + name: ta + namespace: ($namespace) +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: (join('-', ['collector', $namespace])) +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: collector-prometheuscr +subjects: +- kind: ServiceAccount + name: collector + namespace: ($namespace) +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: prometheus-cr +spec: + config: | + receivers: + prometheus: + config: + scrape_configs: [] + + processors: + + exporters: + prometheus: + endpoint: 0.0.0.0:9090 + service: + pipelines: + metrics: + receivers: [prometheus] + exporters: [prometheus] + mode: statefulset + serviceAccount: collector + targetAllocator: + enabled: true + prometheusCR: + enabled: true + scrapeInterval: 1s + podMonitorNamespaceSelector: {} + serviceMonitorNamespaceSelector: {} + scrapeConfigNamespaceSelector: {} + probeNamespaceSelector: {} + serviceAccount: ta From c0bf336a73fce6b1af760f2b5baf314b21c7632a Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Thu, 9 Jan 2025 22:04:58 +0100 Subject: [PATCH 5/6] make reset --- config/manager/kustomization.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 40c0846afa..5c5f0b84cb 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,7 +1,2 @@ resources: - manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: controller - newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator From 636b801c26de58040f140bfb8fbfbabee6aad95c Mon Sep 17 00:00:00 2001 From: Alessio Trivisonno Date: Thu, 9 Jan 2025 22:10:56 +0100 Subject: [PATCH 6/6] fix e2e tests --- .../03-assert.yaml | 20 +-- .../03-install.yaml | 135 ------------------ 2 files changed, 1 insertion(+), 154 deletions(-) diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml index 79c1f8876c..2a4db9ff15 100644 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml @@ -1,20 +1,3 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: prometheus-cr-collector -status: - readyReplicas: 1 - replicas: 1 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: prometheus-cr-targetallocator -status: - observedGeneration: 1 - readyReplicas: 1 - replicas: 1 ---- apiVersion: v1 data: targetallocator.yaml: @@ -24,5 +7,4 @@ data: ( contains(@, join(':', ['scrape_config_namespace_selector', '{}'])) ): true kind: ConfigMap metadata: - name: prometheus-cr-v1beta1-targetallocator ---- \ No newline at end of file + name: prometheus-cr-v1beta1-targetallocator \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml index 3eeb8fc9e0..a4e2aca6d6 100644 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml @@ -1,134 +1,3 @@ -apiVersion: v1 -automountServiceAccountToken: true -kind: ServiceAccount -metadata: - name: ta ---- -apiVersion: v1 -automountServiceAccountToken: true -kind: ServiceAccount -metadata: - name: collector ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: targetallocator-prometheuscr -rules: -- apiGroups: - - "" - resources: - - pods - - nodes - - services - - endpoints - - configmaps - - secrets - - namespaces - verbs: - - get - - watch - - list -- apiGroups: - - apps - resources: - - statefulsets - - services - - endpoints - verbs: - - get - - watch - - list -- apiGroups: - - discovery.k8s.io - resources: - - endpointslices - verbs: - - get - - watch - - list -- apiGroups: - - networking.k8s.io - resources: - - ingresses - verbs: - - get - - watch - - list -- apiGroups: - - monitoring.coreos.com - resources: - - servicemonitors - - podmonitors - - scrapeconfigs - - probes - verbs: - - get - - watch - - list -- nonResourceURLs: - - /metrics - verbs: - - get ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: collector-prometheuscr -rules: -- apiGroups: - - "" - resources: - - pods - - nodes - - nodes/metrics - - services - - endpoints - - namespaces - verbs: - - get - - watch - - list -- apiGroups: - - networking.k8s.io - resources: - - ingresses - verbs: - - get - - watch - - list -- nonResourceURLs: - - /metrics - - /metrics/cadvisor - verbs: - - get ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: (join('-', ['ta', $namespace])) -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: targetallocator-prometheuscr -subjects: -- kind: ServiceAccount - name: ta - namespace: ($namespace) ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: (join('-', ['collector', $namespace])) -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: collector-prometheuscr -subjects: -- kind: ServiceAccount - name: collector - namespace: ($namespace) ---- apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: @@ -157,8 +26,4 @@ spec: prometheusCR: enabled: true scrapeInterval: 1s - podMonitorNamespaceSelector: {} - serviceMonitorNamespaceSelector: {} - scrapeConfigNamespaceSelector: {} - probeNamespaceSelector: {} serviceAccount: ta