@@ -49,6 +49,7 @@ import (
49
49
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
50
50
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
51
51
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
52
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
52
53
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
53
54
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
54
55
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
@@ -758,6 +759,12 @@ func TestExecutePlanDynamicResources(t *testing.T) {
758
759
}
759
760
}
760
761
762
+ func withStatus (catalogSource v1alpha1.CatalogSource , status v1alpha1.CatalogSourceStatus ) * v1alpha1.CatalogSource {
763
+ copy := catalogSource .DeepCopy ()
764
+ copy .Status = status
765
+ return copy
766
+ }
767
+
761
768
func TestSyncCatalogSources (t * testing.T ) {
762
769
clockFake := utilclock .NewFakeClock (time .Date (2018 , time .January , 26 , 20 , 40 , 0 , 0 , time .UTC ))
763
770
now := metav1 .NewTime (clockFake .Now ())
@@ -786,14 +793,15 @@ func TestSyncCatalogSources(t *testing.T) {
786
793
},
787
794
}
788
795
tests := []struct {
789
- testName string
790
- namespace string
791
- catalogSource * v1alpha1.CatalogSource
792
- k8sObjs []runtime.Object
793
- configMap * corev1.ConfigMap
794
- expectedStatus * v1alpha1.CatalogSourceStatus
795
- expectedObjs []runtime.Object
796
- expectedError error
796
+ testName string
797
+ namespace string
798
+ catalogSource * v1alpha1.CatalogSource
799
+ k8sObjs []runtime.Object
800
+ configMap * corev1.ConfigMap
801
+ expectedStatus * v1alpha1.CatalogSourceStatus
802
+ expectedObjs []runtime.Object
803
+ expectedError error
804
+ existingSources []sourceAddress
797
805
}{
798
806
{
799
807
testName : "CatalogSourceWithInvalidSourceType" ,
@@ -1013,6 +1021,47 @@ func TestSyncCatalogSources(t *testing.T) {
1013
1021
},
1014
1022
expectedError : nil ,
1015
1023
},
1024
+ {
1025
+ testName : "GRPCConnectionStateAddressIsUpdated" ,
1026
+ namespace : "cool-namespace" ,
1027
+ catalogSource : withStatus (* grpcCatalog , v1alpha1.CatalogSourceStatus {
1028
+ RegistryServiceStatus : & v1alpha1.RegistryServiceStatus {
1029
+ Protocol : "grpc" ,
1030
+ ServiceName : "cool-catalog" ,
1031
+ ServiceNamespace : "cool-namespace" ,
1032
+ Port : "50051" ,
1033
+ CreatedAt : now ,
1034
+ },
1035
+ GRPCConnectionState : & v1alpha1.GRPCConnectionState {
1036
+ Address : "..svc:" , // Needs to be updated to cool-catalog.cool-namespace.svc:50051
1037
+ },
1038
+ }),
1039
+ k8sObjs : []runtime.Object {
1040
+ pod (* grpcCatalog ),
1041
+ service (grpcCatalog .GetName (), grpcCatalog .GetNamespace ()),
1042
+ },
1043
+ existingSources : []sourceAddress {
1044
+ {
1045
+ sourceKey : registry.CatalogKey {Name : "cool-catalog" , Namespace : "cool-namespace" },
1046
+ address : "cool-catalog.cool-namespace.svc:50051" ,
1047
+ },
1048
+ },
1049
+ expectedStatus : & v1alpha1.CatalogSourceStatus {
1050
+ RegistryServiceStatus : & v1alpha1.RegistryServiceStatus {
1051
+ Protocol : "grpc" ,
1052
+ ServiceName : "cool-catalog" ,
1053
+ ServiceNamespace : "cool-namespace" ,
1054
+ Port : "50051" ,
1055
+ CreatedAt : now ,
1056
+ },
1057
+ GRPCConnectionState : & v1alpha1.GRPCConnectionState {
1058
+ Address : "cool-catalog.cool-namespace.svc:50051" ,
1059
+ LastObservedState : "" ,
1060
+ LastConnectTime : now ,
1061
+ },
1062
+ },
1063
+ expectedError : nil ,
1064
+ },
1016
1065
}
1017
1066
for _ , tt := range tests {
1018
1067
t .Run (tt .testName , func (t * testing.T ) {
@@ -1023,7 +1072,7 @@ func TestSyncCatalogSources(t *testing.T) {
1023
1072
ctx , cancel := context .WithCancel (context .TODO ())
1024
1073
defer cancel ()
1025
1074
1026
- op , err := NewFakeOperator (ctx , tt .namespace , []string {tt .namespace }, withClock (clockFake ), withClientObjs (clientObjs ... ), withK8sObjs (tt .k8sObjs ... ))
1075
+ op , err := NewFakeOperator (ctx , tt .namespace , []string {tt .namespace }, withClock (clockFake ), withClientObjs (clientObjs ... ), withK8sObjs (tt .k8sObjs ... ), withSources ( tt . existingSources ... ) )
1027
1076
require .NoError (t , err )
1028
1077
1029
1078
// Run sync
@@ -1040,6 +1089,13 @@ func TestSyncCatalogSources(t *testing.T) {
1040
1089
require .NotEmpty (t , updated )
1041
1090
1042
1091
if tt .expectedStatus != nil {
1092
+ if tt .expectedStatus .GRPCConnectionState != nil {
1093
+ updated .Status .GRPCConnectionState .LastConnectTime = now
1094
+ // Ignore LastObservedState difference if an expected LastObservedState is no provided
1095
+ if tt .expectedStatus .GRPCConnectionState .LastObservedState == "" {
1096
+ updated .Status .GRPCConnectionState .LastObservedState = ""
1097
+ }
1098
+ }
1043
1099
require .NotEmpty (t , updated .Status )
1044
1100
require .Equal (t , * tt .expectedStatus , updated .Status )
1045
1101
@@ -1384,6 +1440,7 @@ type fakeOperatorConfig struct {
1384
1440
resolver resolver.StepResolver
1385
1441
recorder record.EventRecorder
1386
1442
reconciler reconciler.RegistryReconcilerFactory
1443
+ sources []sourceAddress
1387
1444
}
1388
1445
1389
1446
// fakeOperatorOption applies an option to the given fake operator configuration.
@@ -1395,6 +1452,12 @@ func withResolver(res resolver.StepResolver) fakeOperatorOption {
1395
1452
}
1396
1453
}
1397
1454
1455
+ func withSources (sources ... sourceAddress ) fakeOperatorOption {
1456
+ return func (config * fakeOperatorConfig ) {
1457
+ config .sources = sources
1458
+ }
1459
+ }
1460
+
1398
1461
func withReconciler (rec reconciler.RegistryReconcilerFactory ) fakeOperatorOption {
1399
1462
return func (config * fakeOperatorConfig ) {
1400
1463
config .reconciler = rec
@@ -1431,6 +1494,11 @@ func withFakeClientOptions(options ...clientfake.Option) fakeOperatorOption {
1431
1494
}
1432
1495
}
1433
1496
1497
+ type sourceAddress struct {
1498
+ address string
1499
+ sourceKey registry.CatalogKey
1500
+ }
1501
+
1434
1502
// NewFakeOperator creates a new operator using fake clients.
1435
1503
func NewFakeOperator (ctx context.Context , namespace string , namespaces []string , fakeOptions ... fakeOperatorOption ) (* Operator , error ) {
1436
1504
// Apply options to default config
@@ -1548,6 +1616,9 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
1548
1616
1549
1617
op .RunInformers (ctx )
1550
1618
op .sources .Start (ctx )
1619
+ for _ , source := range config .sources {
1620
+ op .sources .Add (source .sourceKey , source .address )
1621
+ }
1551
1622
1552
1623
if ok := cache .WaitForCacheSync (ctx .Done (), op .HasSynced ); ! ok {
1553
1624
return nil , fmt .Errorf ("failed to wait for caches to sync" )
0 commit comments