@@ -21,9 +21,6 @@ import (
21
21
22
22
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
23
23
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
24
- "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
25
- "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
26
- "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
27
24
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
28
25
)
29
26
@@ -32,61 +29,50 @@ const (
32
29
)
33
30
34
31
func ConfigMap (params manifests.Params ) (* corev1.ConfigMap , error ) {
35
- name := naming .TAConfigMap (params .OtelCol .Name )
36
- labels := Labels (params .OtelCol , name )
37
- // TODO: https://github.com/open-telemetry/opentelemetry-operator/issues/2603
38
- cfgStr , err := params .OtelCol .Spec .Config .Yaml ()
39
- if err != nil {
40
- return & corev1.ConfigMap {}, err
41
- }
42
-
43
- // Collector supports environment variable substitution, but the TA does not.
44
- // TA ConfigMap should have a single "$", as it does not support env var substitution
45
- prometheusReceiverConfig , err := adapters .UnescapeDollarSignsInPromConfig (cfgStr )
46
- if err != nil {
47
- return & corev1.ConfigMap {}, err
48
- }
32
+ instance := params .TargetAllocator
33
+ name := naming .TAConfigMap (instance .Name )
34
+ labels := Labels (instance , name )
35
+ taSpec := instance .Spec
49
36
50
37
taConfig := make (map [interface {}]interface {})
51
38
prometheusCRConfig := make (map [interface {}]interface {})
52
- collectorSelectorLabels := manifestutils .SelectorLabels (params .OtelCol .ObjectMeta , collector .ComponentOpenTelemetryCollector )
53
- taConfig ["collector_selector" ] = map [string ]any {
54
- "matchlabels" : collectorSelectorLabels ,
55
- }
39
+ taConfig ["collector_selector" ] = taSpec .CollectorSelector
56
40
// The below instruction is here for compatibility with the previous target allocator version
57
41
// TODO: Drop it after 3 more versions
58
- taConfig ["label_selector" ] = collectorSelectorLabels
59
- // We only take the "config" from the returned object, if it's present
60
- if prometheusConfig , ok := prometheusReceiverConfig ["config" ]; ok {
61
- taConfig ["config" ] = prometheusConfig
42
+ taConfig ["label_selector" ] = taSpec .CollectorSelector .MatchLabels
43
+
44
+ // Add scrape configs if present
45
+ if instance .Spec .ScrapeConfigs != nil {
46
+ taConfig ["config" ] = map [string ]interface {}{
47
+ "scrape_configs" : instance .Spec .ScrapeConfigs ,
48
+ }
62
49
}
63
50
64
- if len (params . OtelCol . Spec . TargetAllocator .AllocationStrategy ) > 0 {
65
- taConfig ["allocation_strategy" ] = params . OtelCol . Spec . TargetAllocator .AllocationStrategy
51
+ if len (taSpec .AllocationStrategy ) > 0 {
52
+ taConfig ["allocation_strategy" ] = taSpec .AllocationStrategy
66
53
} else {
67
54
taConfig ["allocation_strategy" ] = v1beta1 .TargetAllocatorAllocationStrategyConsistentHashing
68
55
}
56
+ taConfig ["filter_strategy" ] = taSpec .FilterStrategy
69
57
70
- taConfig ["filter_strategy" ] = params .OtelCol .Spec .TargetAllocator .FilterStrategy
71
-
72
- if params .OtelCol .Spec .TargetAllocator .PrometheusCR .ScrapeInterval .Size () > 0 {
73
- prometheusCRConfig ["scrape_interval" ] = params .OtelCol .Spec .TargetAllocator .PrometheusCR .ScrapeInterval .Duration
58
+ if taSpec .PrometheusCR .ScrapeInterval .Size () > 0 {
59
+ prometheusCRConfig ["scrape_interval" ] = taSpec .PrometheusCR .ScrapeInterval .Duration
74
60
}
75
61
76
- prometheusCRConfig ["service_monitor_selector" ] = params . OtelCol . Spec . TargetAllocator .PrometheusCR .ServiceMonitorSelector
62
+ prometheusCRConfig ["service_monitor_selector" ] = taSpec .PrometheusCR .ServiceMonitorSelector
77
63
78
64
// The below instruction is here for compatibility with the previous target allocator version
79
65
// TODO: Drop it after 3 more versions
80
- if params . OtelCol . Spec . TargetAllocator .PrometheusCR .ServiceMonitorSelector != nil {
81
- taConfig ["service_monitor_selector" ] = & params . OtelCol . Spec . TargetAllocator .PrometheusCR .ServiceMonitorSelector .MatchLabels
66
+ if taSpec .PrometheusCR .ServiceMonitorSelector != nil {
67
+ taConfig ["service_monitor_selector" ] = & taSpec .PrometheusCR .ServiceMonitorSelector .MatchLabels
82
68
}
83
69
84
- prometheusCRConfig ["pod_monitor_selector" ] = params . OtelCol . Spec . TargetAllocator .PrometheusCR .PodMonitorSelector
70
+ prometheusCRConfig ["pod_monitor_selector" ] = taSpec .PrometheusCR .PodMonitorSelector
85
71
86
72
// The below instruction is here for compatibility with the previous target allocator version
87
73
// TODO: Drop it after 3 more versions
88
- if params . OtelCol . Spec . TargetAllocator .PrometheusCR .PodMonitorSelector != nil {
89
- taConfig ["pod_monitor_selector" ] = & params . OtelCol . Spec . TargetAllocator .PrometheusCR .PodMonitorSelector .MatchLabels
74
+ if taSpec .PrometheusCR .PodMonitorSelector != nil {
75
+ taConfig ["pod_monitor_selector" ] = & taSpec .PrometheusCR .PodMonitorSelector .MatchLabels
90
76
}
91
77
92
78
if len (prometheusCRConfig ) > 0 {
@@ -101,9 +87,9 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
101
87
return & corev1.ConfigMap {
102
88
ObjectMeta : metav1.ObjectMeta {
103
89
Name : name ,
104
- Namespace : params . OtelCol .Namespace ,
90
+ Namespace : instance .Namespace ,
105
91
Labels : labels ,
106
- Annotations : params . OtelCol .Annotations ,
92
+ Annotations : instance .Annotations ,
107
93
},
108
94
Data : map [string ]string {
109
95
targetAllocatorFilename : string (taConfigYAML ),
0 commit comments