@@ -46,19 +46,23 @@ import (
46
46
)
47
47
48
48
const (
49
- serviceClassGUID = "SCGUID"
50
- planGUID = "PGUID"
51
- instanceGUID = "IGUID"
52
- bindingGUID = "BGUID"
53
-
54
- testBrokerName = "test-broker"
55
- testServiceClassName = "test-serviceclass"
56
- testPlanName = "test-plan"
57
- testInstanceName = "test-instance"
58
- testBindingName = "test-binding"
59
- testNamespace = "test-ns"
60
- testBindingSecretName = "test-secret"
61
- testOperation = "test-operation"
49
+ serviceClassGUID = "SCGUID"
50
+ planGUID = "PGUID"
51
+ nonbindableServiceClassGUID = "UNBINDABLE-SERVICE"
52
+ nonbindablePlanGUID = "UNBINDABLE-PLAN"
53
+ instanceGUID = "IGUID"
54
+ bindingGUID = "BGUID"
55
+
56
+ testBrokerName = "test-broker"
57
+ testServiceClassName = "test-serviceclass"
58
+ testNonbindableServiceClassName = "test-unbindable-serviceclass"
59
+ testPlanName = "test-plan"
60
+ testNonbindablePlanName = "test-unbindable-plan"
61
+ testInstanceName = "test-instance"
62
+ testBindingName = "test-binding"
63
+ testNamespace = "test-ns"
64
+ testBindingSecretName = "test-secret"
65
+ testOperation = "test-operation"
62
66
)
63
67
64
68
const testCatalog = `{
@@ -206,12 +210,13 @@ func getTestBrokerWithStatus(status v1alpha1.ConditionStatus) *v1alpha1.Broker {
206
210
return broker
207
211
}
208
212
209
- // service class wired to the result of getTestBroker()
213
+ // a bindable service class wired to the result of getTestBroker()
210
214
func getTestServiceClass () * v1alpha1.ServiceClass {
211
215
return & v1alpha1.ServiceClass {
212
216
ObjectMeta : metav1.ObjectMeta {Name : testServiceClassName },
213
217
BrokerName : testBrokerName ,
214
218
OSBGUID : serviceClassGUID ,
219
+ Bindable : true ,
215
220
Plans : []v1alpha1.ServicePlan {{
216
221
Name : testPlanName ,
217
222
OSBFree : true ,
@@ -220,6 +225,21 @@ func getTestServiceClass() *v1alpha1.ServiceClass {
220
225
}
221
226
}
222
227
228
+ // an unbindable service class wired to the result of getTestBroker()
229
+ func getTestNonbindableServiceClass () * v1alpha1.ServiceClass {
230
+ return & v1alpha1.ServiceClass {
231
+ ObjectMeta : metav1.ObjectMeta {Name : testNonbindableServiceClassName },
232
+ BrokerName : testBrokerName ,
233
+ OSBGUID : nonbindableServiceClassGUID ,
234
+ Bindable : false ,
235
+ Plans : []v1alpha1.ServicePlan {{
236
+ Name : testNonbindablePlanName ,
237
+ OSBFree : true ,
238
+ OSBGUID : nonbindablePlanGUID ,
239
+ }},
240
+ }
241
+ }
242
+
223
243
// broker catalog that provides the service class named in of
224
244
// getTestServiceClass()
225
245
func getTestCatalog () * brokerapi.Catalog {
@@ -229,6 +249,7 @@ func getTestCatalog() *brokerapi.Catalog {
229
249
Name : testServiceClassName ,
230
250
ID : serviceClassGUID ,
231
251
Description : "a test service" ,
252
+ Bindable : true ,
232
253
Plans : []brokerapi.ServicePlan {
233
254
{
234
255
Name : testPlanName ,
@@ -254,6 +275,15 @@ func getTestInstance() *v1alpha1.Instance {
254
275
}
255
276
}
256
277
278
+ // an isntance referencing the result of getTestNonbindableServiceClass
279
+ func getTestNonbindableInstance () * v1alpha1.Instance {
280
+ i := getTestInstance ()
281
+ i .Spec .ServiceClassName = testNonbindableServiceClassName
282
+ i .Spec .PlanName = testNonbindablePlanName
283
+
284
+ return i
285
+ }
286
+
257
287
// getTestInstanceAsync returns an instance in async mode
258
288
func getTestInstanceAsyncProvisioning (operation string ) * v1alpha1.Instance {
259
289
instance := getTestInstance ()
@@ -1981,6 +2011,41 @@ func TestReconcileBindingWithParameters(t *testing.T) {
1981
2011
}
1982
2012
}
1983
2013
2014
+ func TestReconcileBindingNonbindableServiceClass (t * testing.T ) {
2015
+ _ , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t )
2016
+
2017
+ fakeBrokerClient .CatalogClient .RetCatalog = getTestCatalog ()
2018
+
2019
+ sharedInformers .Brokers ().Informer ().GetStore ().Add (getTestBroker ())
2020
+ sharedInformers .ServiceClasses ().Informer ().GetStore ().Add (getTestNonbindableServiceClass ())
2021
+ sharedInformers .Instances ().Informer ().GetStore ().Add (getTestNonbindableInstance ())
2022
+
2023
+ binding := & v1alpha1.Binding {
2024
+ ObjectMeta : metav1.ObjectMeta {Name : testBindingName , Namespace : testNamespace },
2025
+ Spec : v1alpha1.BindingSpec {
2026
+ InstanceRef : v1.LocalObjectReference {Name : testInstanceName },
2027
+ OSBGUID : bindingGUID ,
2028
+ },
2029
+ }
2030
+
2031
+ testController .reconcileBinding (binding )
2032
+
2033
+ actions := fakeCatalogClient .Actions ()
2034
+ assertNumberOfActions (t , actions , 1 )
2035
+
2036
+ // There should only be one action that says binding was created
2037
+ updatedBinding := assertUpdateStatus (t , actions [0 ], binding )
2038
+ assertBindingReadyFalse (t , updatedBinding , errorNonbindableServiceClassReason )
2039
+
2040
+ events := getRecordedEvents (testController )
2041
+ assertNumEvents (t , events , 1 )
2042
+
2043
+ expectedEvent := api .EventTypeWarning + " " + errorNonbindableServiceClassReason + ` Binding "test-ns/test-binding" references a non-bindable ServiceClass "test-unbindable-serviceclass"`
2044
+ if e , a := expectedEvent , events [0 ]; e != a {
2045
+ t .Fatalf ("Received unexpected event: %v" , a )
2046
+ }
2047
+ }
2048
+
1984
2049
func TestReconcileBindingFailsWithInstanceAsyncOngoing (t * testing.T ) {
1985
2050
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t )
1986
2051
0 commit comments