@@ -297,6 +297,63 @@ prometheus_cr:
297
297
assert .Equal (t , expectedLabels , actual .Labels )
298
298
assert .Equal (t , expectedData , actual .Data )
299
299
})
300
+
301
+ t .Run ("should return expected target allocator config map allocation fallback strategy" , func (t * testing.T ) {
302
+ expectedLabels ["app.kubernetes.io/component" ] = "opentelemetry-targetallocator"
303
+ expectedLabels ["app.kubernetes.io/name" ] = "my-instance-targetallocator"
304
+
305
+ cfg := config .New (config .WithCertManagerAvailability (certmanager .Available ))
306
+
307
+ flgs := featuregate .Flags (colfg .GlobalRegistry ())
308
+ err := flgs .Parse ([]string {"--feature-gates=operator.targetallocator.fallbackstrategy" })
309
+ require .NoError (t , err )
310
+
311
+ testParams := Params {
312
+ Collector : collector ,
313
+ TargetAllocator : targetAllocator ,
314
+ Config : cfg ,
315
+ }
316
+
317
+ expectedData := map [string ]string {
318
+ targetAllocatorFilename : `allocation_fallback_strategy: consistent-hashing
319
+ allocation_strategy: consistent-hashing
320
+ collector_selector:
321
+ matchlabels:
322
+ app.kubernetes.io/component: opentelemetry-collector
323
+ app.kubernetes.io/instance: default.my-instance
324
+ app.kubernetes.io/managed-by: opentelemetry-operator
325
+ app.kubernetes.io/part-of: opentelemetry
326
+ matchexpressions: []
327
+ config:
328
+ scrape_configs:
329
+ - job_name: otel-collector
330
+ scrape_interval: 10s
331
+ static_configs:
332
+ - targets:
333
+ - 0.0.0.0:8888
334
+ - 0.0.0.0:9999
335
+ filter_strategy: relabel-config
336
+ https:
337
+ ca_file_path: /tls/ca.crt
338
+ enabled: true
339
+ listen_addr: :8443
340
+ tls_cert_file_path: /tls/tls.crt
341
+ tls_key_file_path: /tls/tls.key
342
+ prometheus_cr:
343
+ enabled: true
344
+ pod_monitor_selector: null
345
+ scrape_interval: 30s
346
+ service_monitor_selector: null
347
+ ` ,
348
+ }
349
+
350
+ actual , err := ConfigMap (testParams )
351
+ assert .NoError (t , err )
352
+
353
+ assert .Equal (t , "my-instance-targetallocator" , actual .Name )
354
+ assert .Equal (t , expectedLabels , actual .Labels )
355
+ assert .Equal (t , expectedData , actual .Data )
356
+ })
300
357
}
301
358
302
359
func TestGetScrapeConfigsFromOtelConfig (t * testing.T ) {
0 commit comments