@@ -39,6 +39,7 @@ import (
39
39
"sigs.k8s.io/controller-runtime/pkg/client/fake"
40
40
41
41
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
42
+ "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
42
43
"github.com/open-telemetry/opentelemetry-operator/cmd/operator-opamp-bridge/config"
43
44
"github.com/open-telemetry/opentelemetry-operator/cmd/operator-opamp-bridge/operator"
44
45
)
@@ -147,15 +148,15 @@ type mockOpampClient struct {
147
148
settings types.StartSettings
148
149
}
149
150
150
- func (m * mockOpampClient ) SetCustomCapabilities (customCapabilities * protobufs.CustomCapabilities ) error {
151
+ func (m * mockOpampClient ) SetCustomCapabilities (_ * protobufs.CustomCapabilities ) error {
151
152
return nil
152
153
}
153
154
154
- func (m * mockOpampClient ) SendCustomMessage (message * protobufs.CustomMessage ) (messageSendingChannel chan struct {}, err error ) {
155
+ func (m * mockOpampClient ) SendCustomMessage (_ * protobufs.CustomMessage ) (messageSendingChannel chan struct {}, err error ) {
155
156
return nil , nil
156
157
}
157
158
158
- func (m * mockOpampClient ) RequestConnectionSettings (request * protobufs.ConnectionSettingsRequest ) error {
159
+ func (m * mockOpampClient ) RequestConnectionSettings (_ * protobufs.ConnectionSettingsRequest ) error {
159
160
return nil
160
161
}
161
162
@@ -201,6 +202,7 @@ func (m *mockOpampClient) SetPackageStatuses(_ *protobufs.PackageStatuses) error
201
202
func getFakeApplier (t * testing.T , conf * config.Config , lists ... runtimeClient.ObjectList ) * operator.Client {
202
203
schemeBuilder := runtime .NewSchemeBuilder (func (s * runtime.Scheme ) error {
203
204
s .AddKnownTypes (v1alpha1 .GroupVersion , & v1alpha1.OpenTelemetryCollector {}, & v1alpha1.OpenTelemetryCollectorList {})
205
+ s .AddKnownTypes (v1beta1 .GroupVersion , & v1beta1.OpenTelemetryCollector {}, & v1beta1.OpenTelemetryCollectorList {})
204
206
s .AddKnownTypes (v1 .SchemeGroupVersion , & v1.Pod {}, & v1.PodList {})
205
207
metav1 .AddToGroupVersion (s , v1alpha1 .GroupVersion )
206
208
return nil
@@ -414,14 +416,17 @@ func TestAgent_getHealth(t *testing.T) {
414
416
agent .clock = fakeClock
415
417
err := agent .Start ()
416
418
defer agent .Shutdown ()
419
+
417
420
require .NoError (t , err , "should be able to start agent" )
418
421
if len (tt .args .configs ) > 0 {
419
- require .True (t , len ( tt .args .configs ) == len (tt .want ), "must have an equal amount of configs and checks." )
422
+ require .Len (t , tt .args .configs , len (tt .want ), "must have an equal amount of configs and checks." )
420
423
} else {
421
424
require .Len (t , tt .want , 1 , "must have exactly one want if no config is supplied." )
422
425
require .Equal (t , tt .want [0 ], agent .getHealth ())
423
426
}
427
+
424
428
for i , configMap := range tt .args .configs {
429
+ var data * types.MessageData
425
430
data , err := getMessageDataFromConfigFile (configMap )
426
431
require .NoError (t , err , "should be able to load data" )
427
432
agent .onMessage (tt .args .ctx , data )
@@ -495,7 +500,8 @@ func TestAgent_onMessage(t *testing.T) {
495
500
"name: " + testCollectorName ,
496
501
"namespace: " + testNamespace ,
497
502
"send_batch_size: 10000" ,
498
- "receivers: [otlp]" ,
503
+ "receivers:" ,
504
+ "- otlp" ,
499
505
"status:" ,
500
506
},
501
507
},
@@ -523,7 +529,8 @@ func TestAgent_onMessage(t *testing.T) {
523
529
"name: " + testCollectorName ,
524
530
"namespace: " + testNamespace ,
525
531
"send_batch_size: 10000" ,
526
- "receivers: [otlp]" ,
532
+ "receivers:" ,
533
+ "- otlp" ,
527
534
"status:" ,
528
535
},
529
536
},
@@ -549,7 +556,7 @@ func TestAgent_onMessage(t *testing.T) {
549
556
status : & protobufs.RemoteConfigStatus {
550
557
LastRemoteConfigHash : []byte (invalidYamlConfigHash ),
551
558
Status : protobufs .RemoteConfigStatuses_RemoteConfigStatuses_FAILED ,
552
- ErrorMessage : "error converting YAML to JSON: yaml: line 23: could not find expected ':'" ,
559
+ ErrorMessage : "failed to unmarshal config into v1beta1 API Version: error converting YAML to JSON: yaml: line 23: could not find expected ':'" ,
553
560
},
554
561
},
555
562
},
@@ -571,7 +578,8 @@ func TestAgent_onMessage(t *testing.T) {
571
578
"name: " + testCollectorName ,
572
579
"namespace: " + testNamespace ,
573
580
"send_batch_size: 10000" ,
574
- "receivers: [otlp]" ,
581
+ "receivers:" ,
582
+ "- otlp" ,
575
583
"status:" ,
576
584
},
577
585
},
@@ -655,7 +663,9 @@ func TestAgent_onMessage(t *testing.T) {
655
663
"name: " + testCollectorName ,
656
664
"namespace: " + testNamespace ,
657
665
"send_batch_size: 10000" ,
658
- "processors: [memory_limiter, batch]" ,
666
+ "processors:" ,
667
+ "- memory_limiter" ,
668
+ "- batch" ,
659
669
"replicas: 3" ,
660
670
"status:" ,
661
671
},
@@ -706,7 +716,7 @@ func TestAgent_onMessage(t *testing.T) {
706
716
nextStatus : & protobufs.RemoteConfigStatus {
707
717
LastRemoteConfigHash : []byte (invalidYamlConfigHash ), // The new hash should be of the bad config
708
718
Status : protobufs .RemoteConfigStatuses_RemoteConfigStatuses_FAILED ,
709
- ErrorMessage : "error converting YAML to JSON: yaml: line 23: could not find expected ':'" ,
719
+ ErrorMessage : "failed to unmarshal config into v1beta1 API Version: error converting YAML to JSON: yaml: line 23: could not find expected ':'" ,
710
720
},
711
721
},
712
722
},
@@ -752,7 +762,9 @@ func TestAgent_onMessage(t *testing.T) {
752
762
"name: " + otherCollectorName ,
753
763
"namespace: " + testNamespace ,
754
764
"send_batch_size: 10000" ,
755
- "processors: [memory_limiter, batch]" ,
765
+ "processors:" ,
766
+ "- memory_limiter" ,
767
+ "- batch" ,
756
768
"status:" ,
757
769
},
758
770
},
@@ -799,14 +811,17 @@ func TestAgent_onMessage(t *testing.T) {
799
811
for _ , tt := range tests {
800
812
t .Run (tt .name , func (t * testing.T ) {
801
813
mockClient := & mockOpampClient {}
814
+
802
815
conf := config .NewConfig (logr .Discard ())
803
816
loadErr := config .LoadFromFile (conf , tt .fields .configFile )
804
817
require .NoError (t , loadErr , "should be able to load config" )
818
+
805
819
applier := getFakeApplier (t , conf )
806
820
agent := NewAgent (l , applier , conf , mockClient )
807
821
err := agent .Start ()
808
822
defer agent .Shutdown ()
809
823
require .NoError (t , err , "should be able to start agent" )
824
+
810
825
data , err := getMessageDataFromConfigFile (tt .args .configFile )
811
826
require .NoError (t , err , "should be able to load data" )
812
827
agent .onMessage (tt .args .ctx , data )
@@ -818,17 +833,20 @@ func TestAgent_onMessage(t *testing.T) {
818
833
}
819
834
assert .NotNilf (t , effectiveConfig .ConfigMap .GetConfigMap (), "configmap should have data" )
820
835
for colNameNamespace , expectedContents := range tt .want .contents {
821
- assert .Contains (t , effectiveConfig .ConfigMap .GetConfigMap (), colNameNamespace )
836
+ configFileMap := effectiveConfig .ConfigMap .GetConfigMap ()
837
+ require .Contains (t , configFileMap , colNameNamespace )
838
+ configFileString := string (configFileMap [colNameNamespace ].GetBody ())
822
839
for _ , content := range expectedContents {
823
- asString := string (effectiveConfig .ConfigMap .GetConfigMap ()[colNameNamespace ].GetBody ())
824
- assert .Contains (t , asString , content )
840
+ assert .Contains (t , configFileString , content , "config should contain %s" , content )
825
841
}
826
842
}
827
843
assert .Equal (t , tt .want .status , mockClient .lastStatus )
844
+
828
845
if tt .args .nextConfigFile == nil {
829
846
// Nothing left to do!
830
847
return
831
848
}
849
+
832
850
nextData , err := getMessageDataFromConfigFile (tt .args .nextConfigFile )
833
851
require .NoError (t , err , "should be able to load updated data" )
834
852
agent .onMessage (tt .args .ctx , nextData )
@@ -837,10 +855,11 @@ func TestAgent_onMessage(t *testing.T) {
837
855
assert .Equal (t , nextEffectiveConfig , mockClient .lastEffectiveConfig , "client's config should be updated" )
838
856
assert .NotNilf (t , nextEffectiveConfig .ConfigMap .GetConfigMap (), "configmap should have updated data" )
839
857
for colNameNamespace , expectedContents := range tt .want .nextContents {
840
- assert .Contains (t , nextEffectiveConfig .ConfigMap .GetConfigMap (), colNameNamespace )
858
+ configFileMap := nextEffectiveConfig .ConfigMap .GetConfigMap ()
859
+ require .Contains (t , configFileMap , colNameNamespace )
860
+ configFileString := string (configFileMap [colNameNamespace ].GetBody ())
841
861
for _ , content := range expectedContents {
842
- asString := string (nextEffectiveConfig .ConfigMap .GetConfigMap ()[colNameNamespace ].GetBody ())
843
- assert .Contains (t , asString , content )
862
+ assert .Contains (t , configFileString , content )
844
863
}
845
864
}
846
865
assert .Equal (t , tt .want .nextStatus , mockClient .lastStatus )
0 commit comments