@@ -284,6 +284,19 @@ func getTestNonbindableInstance() *v1alpha1.Instance {
284
284
return i
285
285
}
286
286
287
+ func getTestInstanceWithStatus (status v1alpha1.ConditionStatus ) * v1alpha1.Instance {
288
+ instance := getTestInstance ()
289
+ instance .Status = v1alpha1.InstanceStatus {
290
+ Conditions : []v1alpha1.InstanceCondition {{
291
+ Type : v1alpha1 .InstanceConditionReady ,
292
+ Status : status ,
293
+ LastTransitionTime : metav1 .NewTime (time .Now ().Add (- 5 * time .Minute )),
294
+ }},
295
+ }
296
+
297
+ return instance
298
+ }
299
+
287
300
// getTestInstanceAsync returns an instance in async mode
288
301
func getTestInstanceAsyncProvisioning (operation string ) * v1alpha1.Instance {
289
302
instance := getTestInstance ()
@@ -1925,7 +1938,7 @@ func TestReconcileBindingWithParameters(t *testing.T) {
1925
1938
1926
1939
sharedInformers .Brokers ().Informer ().GetStore ().Add (getTestBroker ())
1927
1940
sharedInformers .ServiceClasses ().Informer ().GetStore ().Add (getTestServiceClass ())
1928
- sharedInformers .Instances ().Informer ().GetStore ().Add (getTestInstance ( ))
1941
+ sharedInformers .Instances ().Informer ().GetStore ().Add (getTestInstanceWithStatus ( v1alpha1 . ConditionTrue ))
1929
1942
1930
1943
binding := & v1alpha1.Binding {
1931
1944
ObjectMeta : metav1.ObjectMeta {Name : testBindingName , Namespace : testNamespace },
@@ -2098,6 +2111,53 @@ func TestReconcileBindingFailsWithInstanceAsyncOngoing(t *testing.T) {
2098
2111
}
2099
2112
}
2100
2113
2114
+ func TestReconcileBindingInstanceNotReady (t * testing.T ) {
2115
+ fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t )
2116
+
2117
+ fakeBrokerClient .CatalogClient .RetCatalog = getTestCatalog ()
2118
+
2119
+ fakeKubeClient .AddReactor ("get" , "namespaces" , func (action clientgotesting.Action ) (bool , runtime.Object , error ) {
2120
+ return true , & v1.Namespace {
2121
+ ObjectMeta : metav1.ObjectMeta {
2122
+ UID : types .UID ("test_ns_uid" ),
2123
+ },
2124
+ }, nil
2125
+ })
2126
+
2127
+ sharedInformers .Brokers ().Informer ().GetStore ().Add (getTestBroker ())
2128
+ sharedInformers .ServiceClasses ().Informer ().GetStore ().Add (getTestServiceClass ())
2129
+ sharedInformers .Instances ().Informer ().GetStore ().Add (getTestInstance ())
2130
+
2131
+ binding := & v1alpha1.Binding {
2132
+ ObjectMeta : metav1.ObjectMeta {Name : testBindingName , Namespace : testNamespace },
2133
+ Spec : v1alpha1.BindingSpec {
2134
+ InstanceRef : v1.LocalObjectReference {Name : testInstanceName },
2135
+ OSBGUID : bindingGUID ,
2136
+ },
2137
+ }
2138
+
2139
+ testController .reconcileBinding (binding )
2140
+
2141
+ if _ , ok := fakeBrokerClient .Bindings [fakebrokerapi .BindingsMapKey (instanceGUID , bindingGUID )]; ok {
2142
+ t .Fatalf ("Unexpected broker binding call" )
2143
+ }
2144
+
2145
+ actions := fakeCatalogClient .Actions ()
2146
+ assertNumberOfActions (t , actions , 1 )
2147
+
2148
+ // There should only be one action that says binding was created
2149
+ updatedBinding := assertUpdateStatus (t , actions [0 ], binding )
2150
+ assertBindingReadyFalse (t , updatedBinding )
2151
+
2152
+ events := getRecordedEvents (testController )
2153
+ assertNumEvents (t , events , 1 )
2154
+
2155
+ expectedEvent := api .EventTypeWarning + " " + errorInstanceNotReadyReason + " " + `Binding cannot begin because referenced instance "test-ns/test-instance" is not ready`
2156
+ if e , a := expectedEvent , events [0 ]; e != a {
2157
+ t .Fatalf ("Received unexpected event: %v" , a )
2158
+ }
2159
+ }
2160
+
2101
2161
func TestReconcileBindingNamespaceError (t * testing.T ) {
2102
2162
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t )
2103
2163
@@ -2499,6 +2559,36 @@ func TestCatalogConversionMultipleServiceClasses(t *testing.T) {
2499
2559
2500
2560
}
2501
2561
2562
+ func TestIsBrokerReady (t * testing.T ) {
2563
+ cases := []struct {
2564
+ name string
2565
+ input * v1alpha1.Instance
2566
+ ready bool
2567
+ }{
2568
+ {
2569
+ name : "ready" ,
2570
+ input : getTestInstanceWithStatus (v1alpha1 .ConditionTrue ),
2571
+ ready : true ,
2572
+ },
2573
+ {
2574
+ name : "no status" ,
2575
+ input : getTestInstance (),
2576
+ ready : false ,
2577
+ },
2578
+ {
2579
+ name : "not ready" ,
2580
+ input : getTestInstanceWithStatus (v1alpha1 .ConditionFalse ),
2581
+ ready : false ,
2582
+ },
2583
+ }
2584
+
2585
+ for _ , tc := range cases {
2586
+ if e , a := tc .ready , isInstanceReady (tc .input ); e != a {
2587
+ t .Errorf ("%v: expected result %v, got %v" , tc .name , e , a )
2588
+ }
2589
+ }
2590
+ }
2591
+
2502
2592
// newTestController creates a new test controller injected with fake clients
2503
2593
// and returns:
2504
2594
//
0 commit comments