@@ -20,13 +20,16 @@ import (
20
20
"k8s.io/client-go/kubernetes/fake"
21
21
"k8s.io/client-go/rest"
22
22
kubeTesting "k8s.io/client-go/testing"
23
+ ctrl "sigs.k8s.io/controller-runtime"
23
24
24
25
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect"
25
26
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/autodetectutils"
26
27
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/certmanager"
27
28
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
28
29
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
29
30
autoRBAC "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/rbac"
31
+ "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/targetallocator"
32
+ "github.com/open-telemetry/opentelemetry-operator/internal/config"
30
33
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
31
34
)
32
35
@@ -349,3 +352,93 @@ func TestCertManagerAvailability(t *testing.T) {
349
352
})
350
353
}
351
354
}
355
+
356
+ func TestConfigChangesOnAutoDetect (t * testing.T ) {
357
+ // prepare
358
+ mock := & mockAutoDetect {
359
+ OpenShiftRoutesAvailabilityFunc : func () (openshift.RoutesAvailability , error ) {
360
+ return openshift .RoutesAvailable , nil
361
+ },
362
+ PrometheusCRsAvailabilityFunc : func () (prometheus.Availability , error ) {
363
+ return prometheus .Available , nil
364
+ },
365
+ RBACPermissionsFunc : func (ctx context.Context ) (autoRBAC.Availability , error ) {
366
+ return autoRBAC .Available , nil
367
+ },
368
+ CertManagerAvailabilityFunc : func (ctx context.Context ) (certmanager.Availability , error ) {
369
+ return certmanager .Available , nil
370
+ },
371
+ TargetAllocatorAvailabilityFunc : func () (targetallocator.Availability , error ) {
372
+ return targetallocator .Available , nil
373
+ },
374
+ }
375
+ cfg := config .New ()
376
+ autodetect .ApplyAutoDetect (mock , & cfg , ctrl .Log .WithName ("autodetect" ))
377
+
378
+ // sanity check
379
+ require .Equal (t , openshift .RoutesNotAvailable , cfg .OpenshiftRoutesAvailability )
380
+ require .Equal (t , prometheus .NotAvailable , cfg .PrometheusCRAvailability )
381
+ require .Equal (t , autoRBAC .NotAvailable , cfg .CreateRBACPermissions )
382
+ require .Equal (t , certmanager .NotAvailable , cfg .CertManagerAvailability )
383
+ require .Equal (t , targetallocator .NotAvailable , cfg .TargetAllocatorAvailability )
384
+
385
+ // test
386
+ err := autodetect .ApplyAutoDetect (mock , & cfg , ctrl .Log .WithName ("test" ))
387
+ require .NoError (t , err )
388
+
389
+ // verify
390
+ assert .Equal (t , openshift .RoutesAvailable , cfg .OpenshiftRoutesAvailability )
391
+ require .Equal (t , prometheus .Available , cfg .PrometheusCRAvailability )
392
+ require .Equal (t , autoRBAC .Available , cfg .CreateRBACPermissions )
393
+ require .Equal (t , certmanager .Available , cfg .CertManagerAvailability )
394
+ require .Equal (t , targetallocator .Available , cfg .TargetAllocatorAvailability )
395
+ }
396
+
397
+ var _ autodetect.AutoDetect = (* mockAutoDetect )(nil )
398
+
399
+ type mockAutoDetect struct {
400
+ OpenShiftRoutesAvailabilityFunc func () (openshift.RoutesAvailability , error )
401
+ PrometheusCRsAvailabilityFunc func () (prometheus.Availability , error )
402
+ RBACPermissionsFunc func (ctx context.Context ) (autoRBAC.Availability , error )
403
+ CertManagerAvailabilityFunc func (ctx context.Context ) (certmanager.Availability , error )
404
+ TargetAllocatorAvailabilityFunc func () (targetallocator.Availability , error )
405
+ }
406
+
407
+ func (m * mockAutoDetect ) FIPSEnabled (_ context.Context ) bool {
408
+ return false
409
+ }
410
+
411
+ func (m * mockAutoDetect ) OpenShiftRoutesAvailability () (openshift.RoutesAvailability , error ) {
412
+ if m .OpenShiftRoutesAvailabilityFunc != nil {
413
+ return m .OpenShiftRoutesAvailabilityFunc ()
414
+ }
415
+ return openshift .RoutesNotAvailable , nil
416
+ }
417
+
418
+ func (m * mockAutoDetect ) PrometheusCRsAvailability () (prometheus.Availability , error ) {
419
+ if m .PrometheusCRsAvailabilityFunc != nil {
420
+ return m .PrometheusCRsAvailabilityFunc ()
421
+ }
422
+ return prometheus .NotAvailable , nil
423
+ }
424
+
425
+ func (m * mockAutoDetect ) RBACPermissions (ctx context.Context ) (autoRBAC.Availability , error ) {
426
+ if m .RBACPermissionsFunc != nil {
427
+ return m .RBACPermissionsFunc (ctx )
428
+ }
429
+ return autoRBAC .NotAvailable , nil
430
+ }
431
+
432
+ func (m * mockAutoDetect ) CertManagerAvailability (ctx context.Context ) (certmanager.Availability , error ) {
433
+ if m .CertManagerAvailabilityFunc != nil {
434
+ return m .CertManagerAvailabilityFunc (ctx )
435
+ }
436
+ return certmanager .NotAvailable , nil
437
+ }
438
+
439
+ func (m * mockAutoDetect ) TargetAllocatorAvailability () (targetallocator.Availability , error ) {
440
+ if m .TargetAllocatorAvailabilityFunc != nil {
441
+ return m .TargetAllocatorAvailabilityFunc ()
442
+ }
443
+ return targetallocator .NotAvailable , nil
444
+ }
0 commit comments