Skip to content

Commit

Permalink
feat: expose namespace selector labels conf
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter0195 committed Dec 23, 2024
1 parent 2b0f9d3 commit a539185
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .chloggen/feat-add-prometheuscr-namespaceselectors.yaml
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions apis/v1beta1/targetallocator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
63 changes: 49 additions & 14 deletions controllers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 8 additions & 0 deletions internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit a539185

Please sign in to comment.