@@ -37,6 +37,7 @@ import (
37
37
k8sfake "k8s.io/client-go/kubernetes/fake"
38
38
"k8s.io/client-go/rest"
39
39
"k8s.io/client-go/tools/cache"
40
+ "k8s.io/client-go/tools/record"
40
41
"k8s.io/client-go/util/workqueue"
41
42
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
42
43
apiregistrationfake "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"
@@ -48,6 +49,7 @@ import (
48
49
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
49
50
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
50
51
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
52
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver"
51
53
"github.com/operator-framework/operator-lifecycle-manager/pkg/fakes"
52
54
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
53
55
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
@@ -1008,6 +1010,163 @@ func TestSyncCatalogSources(t *testing.T) {
1008
1010
}
1009
1011
}
1010
1012
1013
+ func TestSyncResolvingNamespace (t * testing.T ) {
1014
+ clockFake := utilclock .NewFakeClock (time .Date (2018 , time .January , 26 , 20 , 40 , 0 , 0 , time .UTC ))
1015
+ testNamespace := "testNamespace"
1016
+
1017
+ type fields struct {
1018
+ clientOptions []clientfake.Option
1019
+ sourcesLastUpdate metav1.Time
1020
+ resolveErr error
1021
+ existingOLMObjs []runtime.Object
1022
+ existingObjects []runtime.Object
1023
+ }
1024
+ type args struct {
1025
+ obj interface {}
1026
+ }
1027
+ tests := []struct {
1028
+ name string
1029
+ fields fields
1030
+ wantErr error
1031
+ }{
1032
+ {
1033
+ name : "NoError" ,
1034
+ fields : fields {
1035
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
1036
+ existingOLMObjs : []runtime.Object {
1037
+ & v1alpha1.Subscription {
1038
+ TypeMeta : metav1.TypeMeta {
1039
+ Kind : v1alpha1 .SubscriptionKind ,
1040
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
1041
+ },
1042
+ ObjectMeta : metav1.ObjectMeta {
1043
+ Name : "sub" ,
1044
+ Namespace : testNamespace ,
1045
+ },
1046
+ Spec : & v1alpha1.SubscriptionSpec {
1047
+ CatalogSource : "src" ,
1048
+ CatalogSourceNamespace : testNamespace ,
1049
+ },
1050
+ Status : v1alpha1.SubscriptionStatus {
1051
+ CurrentCSV : "" ,
1052
+ State : "" ,
1053
+ },
1054
+ },
1055
+ },
1056
+ },
1057
+ },
1058
+ {
1059
+ name : "NotSatisfiableError" ,
1060
+ fields : fields {
1061
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
1062
+ existingOLMObjs : []runtime.Object {
1063
+ & v1alpha1.Subscription {
1064
+ TypeMeta : metav1.TypeMeta {
1065
+ Kind : v1alpha1 .SubscriptionKind ,
1066
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
1067
+ },
1068
+ ObjectMeta : metav1.ObjectMeta {
1069
+ Name : "sub" ,
1070
+ Namespace : testNamespace ,
1071
+ },
1072
+ Spec : & v1alpha1.SubscriptionSpec {
1073
+ CatalogSource : "src" ,
1074
+ CatalogSourceNamespace : testNamespace ,
1075
+ },
1076
+ Status : v1alpha1.SubscriptionStatus {
1077
+ CurrentCSV : "" ,
1078
+ State : "" ,
1079
+ },
1080
+ },
1081
+ },
1082
+ resolveErr : solver.NotSatisfiable {
1083
+ {
1084
+ Installable : resolver .NewSubscriptionInstallable ("a" , nil ),
1085
+ Constraint : resolver .PrettyConstraint (solver .Mandatory (), "something" ),
1086
+ },
1087
+ },
1088
+ },
1089
+ },
1090
+ {
1091
+ name : "OtherError" ,
1092
+ fields : fields {
1093
+ clientOptions : []clientfake.Option {clientfake .WithSelfLinks (t )},
1094
+ existingOLMObjs : []runtime.Object {
1095
+ & v1alpha1.ClusterServiceVersion {
1096
+ ObjectMeta : metav1.ObjectMeta {
1097
+ Name : "csv.v.1" ,
1098
+ Namespace : testNamespace ,
1099
+ },
1100
+ Status : v1alpha1.ClusterServiceVersionStatus {
1101
+ Phase : v1alpha1 .CSVPhaseSucceeded ,
1102
+ },
1103
+ },
1104
+ & v1alpha1.Subscription {
1105
+ TypeMeta : metav1.TypeMeta {
1106
+ Kind : v1alpha1 .SubscriptionKind ,
1107
+ APIVersion : v1alpha1 .SchemeGroupVersion .String (),
1108
+ },
1109
+ ObjectMeta : metav1.ObjectMeta {
1110
+ Name : "sub" ,
1111
+ Namespace : testNamespace ,
1112
+ },
1113
+ Spec : & v1alpha1.SubscriptionSpec {
1114
+ CatalogSource : "src" ,
1115
+ CatalogSourceNamespace : testNamespace ,
1116
+ },
1117
+ Status : v1alpha1.SubscriptionStatus {
1118
+ CurrentCSV : "" ,
1119
+ State : "" ,
1120
+ },
1121
+ },
1122
+ },
1123
+ resolveErr : fmt .Errorf ("some error" ),
1124
+ },
1125
+ wantErr : fmt .Errorf ("some error" ),
1126
+ },
1127
+ }
1128
+ for _ , tt := range tests {
1129
+ t .Run (tt .name , func (t * testing.T ) {
1130
+ // Create test operator
1131
+ ctx , cancel := context .WithCancel (context .TODO ())
1132
+ defer cancel ()
1133
+
1134
+ o , err := NewFakeOperator (ctx , testNamespace , []string {testNamespace }, withClock (clockFake ), withClientObjs (tt .fields .existingOLMObjs ... ), withK8sObjs (tt .fields .existingObjects ... ), withFakeClientOptions (tt .fields .clientOptions ... ))
1135
+ require .NoError (t , err )
1136
+
1137
+ o .reconciler = & fakes.FakeRegistryReconcilerFactory {
1138
+ ReconcilerForSourceStub : func (source * v1alpha1.CatalogSource ) reconciler.RegistryReconciler {
1139
+ return & fakes.FakeRegistryReconciler {
1140
+ EnsureRegistryServerStub : func (source * v1alpha1.CatalogSource ) error {
1141
+ return nil
1142
+ },
1143
+ }
1144
+ },
1145
+ }
1146
+
1147
+ o .sourcesLastUpdate .Set (tt .fields .sourcesLastUpdate .Time )
1148
+ o .resolver = & fakes.FakeStepResolver {
1149
+ ResolveStepsStub : func (string , resolver.SourceQuerier ) ([]* v1alpha1.Step , []v1alpha1.BundleLookup , []* v1alpha1.Subscription , error ) {
1150
+ return nil , nil , nil , tt .fields .resolveErr
1151
+ },
1152
+ }
1153
+
1154
+ namespace := & corev1.Namespace {
1155
+ ObjectMeta : metav1.ObjectMeta {
1156
+ Name : testNamespace ,
1157
+ },
1158
+ }
1159
+
1160
+ err = o .syncResolvingNamespace (namespace )
1161
+ if tt .wantErr != nil {
1162
+ require .Equal (t , tt .wantErr , err )
1163
+ } else {
1164
+ require .NoError (t , err )
1165
+ }
1166
+ })
1167
+ }
1168
+ }
1169
+
1011
1170
func TestCompetingCRDOwnersExist (t * testing.T ) {
1012
1171
1013
1172
testNamespace := "default"
@@ -1102,6 +1261,7 @@ type fakeOperatorConfig struct {
1102
1261
clientOptions []clientfake.Option
1103
1262
logger * logrus.Logger
1104
1263
resolver resolver.StepResolver
1264
+ recorder record.EventRecorder
1105
1265
reconciler reconciler.RegistryReconcilerFactory
1106
1266
}
1107
1267
@@ -1157,6 +1317,7 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
1157
1317
logger : logrus .StandardLogger (),
1158
1318
clock : utilclock.RealClock {},
1159
1319
resolver : & fakes.FakeStepResolver {},
1320
+ recorder : & record.FakeRecorder {},
1160
1321
}
1161
1322
for _ , option := range fakeOptions {
1162
1323
option (config )
@@ -1242,6 +1403,7 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
1242
1403
), "resolver" ),
1243
1404
resolver : config .resolver ,
1244
1405
reconciler : config .reconciler ,
1406
+ recorder : config .recorder ,
1245
1407
clientAttenuator : scoped .NewClientAttenuator (logger , & rest.Config {}, opClientFake , clientFake , dynamicClientFake ),
1246
1408
serviceAccountQuerier : scoped .NewUserDefinedServiceAccountQuerier (logger , clientFake ),
1247
1409
catsrcQueueSet : queueinformer .NewEmptyResourceQueueSet (),
0 commit comments