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