@@ -232,9 +232,9 @@ func TestReconcileClusterServiceBrokerExistingServiceClassAndServicePlan(t *test
232
232
assertNumberOfActions (t , actions , 6 )
233
233
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
234
234
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
235
- assertCreate (t , actions [2 ], testClusterServicePlan )
236
- assertCreate (t , actions [3 ], testClusterServicePlanNonbindable )
237
- assertUpdate (t , actions [4 ], testClusterServiceClass )
235
+ assertUpdate (t , actions [2 ], testClusterServiceClass )
236
+ assertCreate (t , actions [3 ], testClusterServicePlan )
237
+ assertCreate (t , actions [4 ], testClusterServicePlanNonbindable )
238
238
239
239
// 4 update action for broker status subresource
240
240
updatedClusterServiceBroker := assertUpdateStatus (t , actions [5 ], getTestClusterServiceBroker ())
@@ -281,10 +281,10 @@ func TestReconcileClusterServiceBrokerRemovedClusterServiceClass(t *testing.T) {
281
281
assertNumberOfActions (t , actions , 7 )
282
282
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
283
283
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
284
- assertCreate (t , actions [2 ], testClusterServicePlan )
285
- assertCreate (t , actions [3 ], testClusterServicePlanNonbindable )
286
- assertUpdate (t , actions [4 ], testClusterServiceClass )
287
- assertUpdateStatus (t , actions [5 ], testRemovedClusterServiceClass )
284
+ assertUpdate (t , actions [2 ], testClusterServiceClass )
285
+ assertUpdateStatus (t , actions [3 ], testRemovedClusterServiceClass )
286
+ assertCreate (t , actions [4 ], testClusterServicePlan )
287
+ assertCreate (t , actions [5 ], testClusterServicePlanNonbindable )
288
288
289
289
updatedClusterServiceBroker := assertUpdateStatus (t , actions [6 ], getTestClusterServiceBroker ())
290
290
assertClusterServiceBrokerReadyTrue (t , updatedClusterServiceBroker )
@@ -336,10 +336,10 @@ func TestReconcileClusterServiceBrokerRemovedClusterServicePlan(t *testing.T) {
336
336
assertNumberOfActions (t , actions , 7 )
337
337
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
338
338
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
339
- assertCreate (t , actions [2 ], testClusterServicePlan )
340
- assertCreate (t , actions [3 ], testClusterServicePlanNonbindable )
341
- assertUpdateStatus (t , actions [4 ], testRemovedClusterServicePlan )
342
- assertUpdate (t , actions [5 ], testClusterServiceClass )
339
+ assertUpdate (t , actions [2 ], testClusterServiceClass )
340
+ assertCreate (t , actions [3 ], testClusterServicePlan )
341
+ assertCreate (t , actions [4 ], testClusterServicePlanNonbindable )
342
+ assertUpdateStatus (t , actions [5 ], testRemovedClusterServicePlan )
343
343
344
344
updatedClusterServiceBroker := assertUpdateStatus (t , actions [6 ], getTestClusterServiceBroker ())
345
345
assertClusterServiceBrokerReadyTrue (t , updatedClusterServiceBroker )
@@ -358,15 +358,54 @@ func TestReconcileClusterServiceBrokerExistingClusterServiceClassDifferentBroker
358
358
testClusterServiceClass := getTestClusterServiceClass ()
359
359
testClusterServiceClass .Spec .ClusterServiceBrokerName = "notTheSame"
360
360
361
+ sharedInformers .ClusterServiceClasses ().Informer ().GetStore ().Add (testClusterServiceClass )
362
+
363
+ if err := testController .reconcileClusterServiceBroker (getTestClusterServiceBroker ()); err == nil {
364
+ t .Fatal ("The same service class should not belong to two different brokers." )
365
+ }
366
+
367
+ brokerActions := fakeClusterServiceBrokerClient .Actions ()
368
+ assertNumberOfClusterServiceBrokerActions (t , brokerActions , 1 )
369
+ assertGetCatalog (t , brokerActions [0 ])
370
+
371
+ actions := fakeCatalogClient .Actions ()
372
+ assertNumberOfActions (t , actions , 3 )
373
+
374
+ listRestrictions := clientgotesting.ListRestrictions {
375
+ Labels : labels .Everything (),
376
+ Fields : fields .OneTermEqualSelector ("spec.clusterServiceBrokerName" , "test-broker" ),
377
+ }
378
+ assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
379
+ assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
380
+ updatedClusterServiceBroker := assertUpdateStatus (t , actions [2 ], getTestClusterServiceBroker ())
381
+ assertClusterServiceBrokerReadyFalse (t , updatedClusterServiceBroker )
382
+
383
+ // verify no kube resources created
384
+ kubeActions := fakeKubeClient .Actions ()
385
+ assertNumberOfActions (t , kubeActions , 0 )
386
+
387
+ events := getRecordedEvents (testController )
388
+ assertNumEvents (t , events , 1 )
389
+
390
+ expectedEvent := corev1 .EventTypeWarning + " " + errorSyncingCatalogReason + ` Error reconciling ClusterServiceClass (K8S: "SCGUID" ExternalName: "test-serviceclass") (broker "test-broker"): ClusterServiceClass (K8S: "SCGUID" ExternalName: "test-serviceclass") already exists for Broker "notTheSame"`
391
+ if e , a := expectedEvent , events [0 ]; e != a {
392
+ t .Fatalf ("Received unexpected event; expected\n %v, got\n %v" , e , a )
393
+ }
394
+ }
395
+
396
+ // TestReconcileClusterServiceBrokerExistingClusterServicePlanDifferentClass simulates catalog
397
+ // refresh where broker lists a service plan which matches an existing, already
398
+ // cataloged service plan but the plan points to a different ClusterServiceClass. Results in an error.
399
+ func TestReconcileClusterServiceBrokerExistingClusterServicePlanDifferentClass (t * testing.T ) {
400
+ fakeKubeClient , fakeCatalogClient , fakeClusterServiceBrokerClient , testController , sharedInformers := newTestController (t , getTestCatalogConfig ())
401
+
361
402
testClusterServicePlan := getTestClusterServicePlan ()
362
403
testClusterServicePlan .Spec .ClusterServiceBrokerName = "notTheSame"
404
+ testClusterServicePlan .Spec .ClusterServiceClassRef = v1beta1.ClusterObjectReference {
405
+ Name : "notTheSameClass" ,
406
+ }
363
407
364
- testClusterServicePlanNonbindable := getTestClusterServicePlanNonbindable ()
365
- testClusterServicePlanNonbindable .Spec .ClusterServiceBrokerName = "notTheSame"
366
-
367
- sharedInformers .ClusterServiceClasses ().Informer ().GetStore ().Add (testClusterServiceClass )
368
408
sharedInformers .ClusterServicePlans ().Informer ().GetStore ().Add (testClusterServicePlan )
369
- sharedInformers .ClusterServicePlans ().Informer ().GetStore ().Add (testClusterServicePlanNonbindable )
370
409
371
410
if err := testController .reconcileClusterServiceBroker (getTestClusterServiceBroker ()); err == nil {
372
411
t .Fatal ("The same service class should not belong to two different brokers." )
@@ -377,15 +416,16 @@ func TestReconcileClusterServiceBrokerExistingClusterServiceClassDifferentBroker
377
416
assertGetCatalog (t , brokerActions [0 ])
378
417
379
418
actions := fakeCatalogClient .Actions ()
380
- assertNumberOfActions (t , actions , 3 )
419
+ assertNumberOfActions (t , actions , 4 )
381
420
382
421
listRestrictions := clientgotesting.ListRestrictions {
383
422
Labels : labels .Everything (),
384
423
Fields : fields .OneTermEqualSelector ("spec.clusterServiceBrokerName" , "test-broker" ),
385
424
}
386
425
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
387
426
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
388
- updatedClusterServiceBroker := assertUpdateStatus (t , actions [2 ], getTestClusterServiceBroker ())
427
+ assertCreate (t , actions [2 ], getTestClusterServiceClass ())
428
+ updatedClusterServiceBroker := assertUpdateStatus (t , actions [3 ], getTestClusterServiceBroker ())
389
429
assertClusterServiceBrokerReadyFalse (t , updatedClusterServiceBroker )
390
430
391
431
// verify no kube resources created
@@ -737,28 +777,26 @@ func TestReconcileClusterServiceBrokerWithReconcileError(t *testing.T) {
737
777
assertGetCatalog (t , brokerActions [0 ])
738
778
739
779
actions := fakeCatalogClient .Actions ()
740
- assertNumberOfActions (t , actions , 6 )
780
+ assertNumberOfActions (t , actions , 4 )
741
781
742
782
listRestrictions := clientgotesting.ListRestrictions {
743
783
Labels : labels .Everything (),
744
784
Fields : fields .OneTermEqualSelector ("spec.clusterServiceBrokerName" , broker .Name ),
745
785
}
746
786
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
747
787
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
748
- assertCreate (t , actions [2 ], getTestClusterServicePlan ())
749
- assertCreate (t , actions [3 ], getTestClusterServicePlanNonbindable ())
750
788
751
789
// the two plans in the catalog as two separate actions
752
790
753
- createSCAction := actions [4 ].(clientgotesting.CreateAction )
791
+ createSCAction := actions [2 ].(clientgotesting.CreateAction )
754
792
createdSC , ok := createSCAction .GetObject ().(* v1beta1.ClusterServiceClass )
755
793
if ! ok {
756
794
t .Fatalf ("couldn't convert to a ClusterServiceClass: %+v" , createSCAction .GetObject ())
757
795
}
758
796
if e , a := getTestClusterServiceClass (), createdSC ; ! reflect .DeepEqual (e , a ) {
759
797
t .Fatalf ("unexpected diff for created ClusterServiceClass: %v,\n \n EXPECTED: %+v\n \n ACTUAL: %+v" , diff .ObjectReflectDiff (e , a ), e , a )
760
798
}
761
- updatedClusterServiceBroker := assertUpdateStatus (t , actions [5 ], broker )
799
+ updatedClusterServiceBroker := assertUpdateStatus (t , actions [3 ], broker )
762
800
assertClusterServiceBrokerReadyFalse (t , updatedClusterServiceBroker )
763
801
764
802
kubeActions := fakeKubeClient .Actions ()
@@ -807,9 +845,9 @@ func TestReconcileClusterServiceBrokerSuccessOnFinalRetry(t *testing.T) {
807
845
808
846
assertList (t , actions [1 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
809
847
assertList (t , actions [2 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
810
- assertCreate (t , actions [3 ], getTestClusterServicePlan () )
811
- assertCreate (t , actions [4 ], getTestClusterServicePlanNonbindable ())
812
- assertCreate (t , actions [5 ], testClusterServiceClass )
848
+ assertCreate (t , actions [3 ], testClusterServiceClass )
849
+ assertCreate (t , actions [4 ], getTestClusterServicePlan ())
850
+ assertCreate (t , actions [5 ], getTestClusterServicePlanNonbindable () )
813
851
814
852
updatedClusterServiceBroker = assertUpdateStatus (t , actions [6 ], getTestClusterServiceBroker ())
815
853
assertClusterServiceBrokerReadyTrue (t , updatedClusterServiceBroker )
@@ -904,9 +942,9 @@ func TestReconcileClusterServiceBrokerWithStatusUpdateError(t *testing.T) {
904
942
905
943
assertList (t , actions [0 ], & v1beta1.ClusterServiceClass {}, listRestrictions )
906
944
assertList (t , actions [1 ], & v1beta1.ClusterServicePlan {}, listRestrictions )
907
- assertCreate (t , actions [2 ], getTestClusterServicePlan () )
908
- assertCreate (t , actions [3 ], getTestClusterServicePlanNonbindable ())
909
- assertCreate (t , actions [4 ], testClusterServiceClass )
945
+ assertCreate (t , actions [2 ], testClusterServiceClass )
946
+ assertCreate (t , actions [3 ], getTestClusterServicePlan ())
947
+ assertCreate (t , actions [4 ], getTestClusterServicePlanNonbindable () )
910
948
911
949
// 4 update action for broker status subresource
912
950
updatedClusterServiceBroker := assertUpdateStatus (t , actions [5 ], getTestClusterServiceBroker ())
0 commit comments