Skip to content

Commit 536dad5

Browse files
committed
wip
1 parent 7bc6c3f commit 536dad5

6 files changed

Lines changed: 9 additions & 35 deletions

File tree

app/actions/service_credential_binding_app_create.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ def event_repository
112112
end
113113

114114
def max_bindings_per_app_service_instance
115-
# TODO: revert !!!
116-
2
117-
# NOTE: This is hard-coded to 1 for now to preserve the old uniqueness behavior.
118-
# TODO: Once the DB migration that drops the unique constraints for service bindings has been released,
119-
# this should be switched to read from config:
120-
# VCAP::CloudController::Config.config.get(:max_service_credential_bindings_per_app_service_instance)
121-
# TODO: Also remove skips in related specs.
115+
VCAP::CloudController::Config.config.get(:max_service_credential_bindings_per_app_service_instance)
122116
end
123117

124118
def app_is_required!

config/cloud_controller.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ directories:
322322
stacks_file: config/stacks.yml
323323
newrelic_enabled: false
324324

325+
max_service_credential_bindings_per_app_service_instance: 1
325326
max_annotations_per_resource: 200
326327
max_labels_per_resource: 50
327328
max_migration_duration_in_minutes: 45

lib/cloud_controller/config_schemas/api_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class ApiSchema < VCAP::Config
410410
optional(:query_raise_on_mismatch) => bool
411411
},
412412

413+
max_service_credential_bindings_per_app_service_instance: Integer,
413414
max_labels_per_resource: Integer,
414415
max_annotations_per_resource: Integer,
415416

lib/cloud_controller/config_schemas/worker_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class WorkerSchema < VCAP::Config
221221

222222
max_manifest_service_binding_poll_duration_in_seconds: Integer,
223223

224+
max_service_credential_bindings_per_app_service_instance: Integer,
224225
max_labels_per_resource: Integer,
225226
max_annotations_per_resource: Integer,
226227
custom_metric_tag_prefix_list: Array,

spec/unit/actions/service_credential_binding_app_create_spec.rb

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module V3
4343

4444
describe '#precursor' do
4545
RSpec.shared_examples 'the credential binding precursor' do
46+
before { TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1) }
47+
4648
it 'returns a service credential binding precursor' do
4749
binding = action.precursor(service_instance, app:, message:)
4850

@@ -69,9 +71,6 @@ module V3
6971
context 'when a binding already exists' do
7072
let!(:binding) { ServiceBinding.make(service_instance:, app:) }
7173

72-
# TODO: Once the unique constraints to allow multiple bindings are removed, this needs to be set to 1
73-
# before { TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1) }
74-
7574
context 'when no last binding operation exists' do
7675
it 'raises an error' do
7776
expect { action.precursor(service_instance, app:, message:) }.to raise_error(
@@ -161,9 +160,6 @@ module V3
161160
end
162161
let(:service_instance2) { ManagedServiceInstance.make(**si_details) }
163162

164-
# TODO: Once the unique constraints to allow multiple bindings are removed, this needs to be set to 1
165-
# before { TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1) }
166-
167163
it 'raises an error when the binding name already exists' do
168164
# First request, should succeed
169165
expect do
@@ -188,9 +184,6 @@ module V3
188184
)
189185
end
190186

191-
# TODO: Once the unique constraints to allow multiple bindings are removed, this needs to be set to 1
192-
# before { TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1) }
193-
194187
it 'raises an error when the app is already bound to the service instance' do
195188
# First request, should succeed
196189
expect do
@@ -209,8 +202,6 @@ module V3
209202
let(:binding_1) { ServiceBinding.make(service_instance: service_instance, app: app, name: nil) }
210203

211204
before do
212-
# TODO: Once the unique constraints to allow multiple bindings are removed, this needs to be set to 1
213-
# TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1)
214205
binding_1.save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
215206
end
216207

@@ -231,9 +222,6 @@ module V3
231222
context 'concurrent credential binding creation' do
232223
let(:name) { nil }
233224

234-
# TODO: Once the unique constraints to allow multiple bindings are removed, this needs to be set to 1
235-
# before { TestConfig.override(max_service_credential_bindings_per_app_service_instance: 1) }
236-
237225
it 'allows only one binding when two creates run in parallel' do
238226
# This test simulates a race condition for concurrent binding creation using a spy on `service_instance`.
239227
# We mock that a second binding is created after the first one acquires a lock and expect an `UnprocessableCreate` error.
@@ -251,11 +239,10 @@ module V3
251239
end
252240

253241
context 'when multiple bindings are allowed' do
254-
before do
255-
# TODO: Remove skip when the service bindings unique constraints are removed
256-
skip 'this test can be enabled when the service bindings unique constraints are removed and max_bindings_per_app_service_instance can be configured'
242+
let(:binding_1) { ServiceBinding.make(service_instance:, app:, name:) }
257243

258-
binding_1 = ServiceBinding.make(service_instance:, app:, name:)
244+
before do
245+
TestConfig.override(max_service_credential_bindings_per_app_service_instance: 3)
259246
binding_2 = ServiceBinding.make(service_instance:, app:, name:)
260247
binding_1.save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
261248
binding_2.save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
@@ -276,8 +263,6 @@ module V3
276263
end
277264

278265
it 'raises an error if one of the bindings is in a failed state' do
279-
TestConfig.override(max_service_credential_bindings_per_app_service_instance: 2)
280-
281266
ServiceBinding.make(service_instance:, app:, name:).save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
282267
ServiceBinding.make(service_instance:, app:, name:).save_with_attributes_and_new_operation({}, { type: 'delete', state: 'failed' })
283268

@@ -304,8 +289,6 @@ module V3
304289
end
305290

306291
it 'raises an error if an existing binding has a different name' do
307-
TestConfig.override(max_service_credential_bindings_per_app_service_instance: 4)
308-
309292
ServiceBinding.make(service_instance: service_instance, app: app, name: 'other-name').
310293
save_with_attributes_and_new_operation({}, { type: 'create', state: 'succeeded' })
311294

spec/unit/lib/cloud_controller/diego/service_binding_files_builder_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ module VCAP::CloudController::Diego
1818
end
1919

2020
context 'when there are multiple bindings with the same name for the same app and service instance' do
21-
# TODO: include !!!
22-
# before do
23-
# # TODO: Remove skip when the service bindings unique constraints are removed
24-
# skip 'this test can be enabled when the service bindings unique constraints are removed and max_bindings_per_app_service_instance can be configured'
25-
# end
26-
2721
let(:newer_binding_created_at) { Time.now.utc - 2.minutes }
2822

2923
let!(:newer_binding) do

0 commit comments

Comments
 (0)