Skip to content

Commit 1bb7636

Browse files
Remove transformation of VCAP_SERVICES attributes in k8s bindings (#4542)
This is not needed as per #4525 (comment) Signed-off-by: Tom Kennedy <[email protected]>
1 parent a8f7659 commit 1bb7636

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

lib/cloud_controller/diego/service_binding_files_builder.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def build_service_binding_k8s
5151
sb_hash.delete(:credentials)&.each { |k, v| total_bytesize += add_file(service_binding_files, name, k.to_s, v) }
5252

5353
# add the rest of the hash; already existing credential keys are overwritten
54-
# VCAP_SERVICES attribute names are transformed (e.g. binding_guid -> binding-guid)
55-
sb_hash.each { |k, v| total_bytesize += add_file(service_binding_files, name, transform_vcap_services_attribute(k.to_s), v) }
54+
sb_hash.each { |k, v| total_bytesize += add_file(service_binding_files, name, k.to_s, v) }
5655

5756
# add the type and provider
5857
label = sb_hash[:label]
@@ -114,14 +113,6 @@ def valid_binding_name?(name)
114113
def valid_file_name?(name)
115114
name.match?(file_naming_convention)
116115
end
117-
118-
def transform_vcap_services_attribute(name)
119-
if %w[binding_guid binding_name instance_guid instance_name syslog_drain_url volume_mounts].include?(name)
120-
name.tr('_', '-')
121-
else
122-
name
123-
end
124-
end
125116
end
126117
end
127118
end

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ module VCAP::CloudController::Diego
1212

1313
RSpec.shared_examples 'mapping of binding metadata' do |name|
1414
it 'maps service binding metadata attributes to files' do
15-
expect(service_binding_files.find { |f| f.path == "#{directory}/binding-guid" }).to have_attributes(content: binding.guid)
15+
expect(service_binding_files.find { |f| f.path == "#{directory}/binding_guid" }).to have_attributes(content: binding.guid)
1616
expect(service_binding_files.find { |f| f.path == "#{directory}/name" }).to have_attributes(content: name || 'binding-name')
17-
expect(service_binding_files.find { |f| f.path == "#{directory}/binding-name" }).to have_attributes(content: 'binding-name') if name.nil?
17+
expect(service_binding_files.find { |f| f.path == "#{directory}/binding_name" }).to have_attributes(content: 'binding-name') if name.nil?
1818
end
1919

2020
context 'when there are multiple bindings with the same name for the same app and service instance' do
@@ -48,8 +48,8 @@ module VCAP::CloudController::Diego
4848

4949
RSpec.shared_examples 'mapping of instance metadata' do |instance_name|
5050
it 'maps service instance metadata attributes to files' do
51-
expect(service_binding_files.find { |f| f.path == "#{directory}/instance-guid" }).to have_attributes(content: instance.guid)
52-
expect(service_binding_files.find { |f| f.path == "#{directory}/instance-name" }).to have_attributes(content: instance_name || 'instance-name')
51+
expect(service_binding_files.find { |f| f.path == "#{directory}/instance_guid" }).to have_attributes(content: instance.guid)
52+
expect(service_binding_files.find { |f| f.path == "#{directory}/instance_name" }).to have_attributes(content: instance_name || 'instance-name')
5353
end
5454
end
5555

@@ -166,7 +166,7 @@ module VCAP::CloudController::Diego
166166
expect(service_binding_files).not_to include(have_attributes(path: 'binding-name/volume_mounts'))
167167
end
168168

169-
include_examples 'expected files', %w[type provider label binding-guid name binding-name instance-guid instance-name plan tags string number boolean array hash]
169+
include_examples 'expected files', %w[type provider label binding_guid name binding_name instance_guid instance_name plan tags string number boolean array hash]
170170

171171
context 'when binding_name is nil' do
172172
let(:binding_name) { nil }
@@ -179,14 +179,14 @@ module VCAP::CloudController::Diego
179179
include_examples 'mapping of tags'
180180
include_examples 'mapping of credentials'
181181

182-
include_examples 'expected files', %w[type provider label binding-guid name instance-guid instance-name plan tags string number boolean array hash]
182+
include_examples 'expected files', %w[type provider label binding_guid name instance_guid instance_name plan tags string number boolean array hash]
183183
end
184184

185185
context 'when syslog_drain_url is set' do
186186
let(:syslog_drain_url) { 'https://syslog.drain' }
187187

188188
it 'maps the attribute to a file' do
189-
expect(service_binding_files.find { |f| f.path == 'binding-name/syslog-drain-url' }).to have_attributes(content: 'https://syslog.drain')
189+
expect(service_binding_files.find { |f| f.path == 'binding-name/syslog_drain_url' }).to have_attributes(content: 'https://syslog.drain')
190190
end
191191

192192
include_examples 'mapping of type and provider'
@@ -197,7 +197,7 @@ module VCAP::CloudController::Diego
197197
include_examples 'mapping of credentials'
198198

199199
include_examples 'expected files',
200-
%w[type provider label binding-guid name binding-name instance-guid instance-name plan tags string number boolean array hash syslog-drain-url]
200+
%w[type provider label binding_guid name binding_name instance_guid instance_name plan tags string number boolean array hash syslog_drain_url]
201201
end
202202

203203
context 'when volume_mounts is set' do
@@ -217,7 +217,7 @@ module VCAP::CloudController::Diego
217217

218218
it 'maps the attribute to a file' do
219219
expect(service_binding_files.find do |f|
220-
f.path == 'binding-name/volume-mounts'
220+
f.path == 'binding-name/volume_mounts'
221221
end).to have_attributes(content: '[{"container_dir":"dir1","device_type":"type1","mode":"mode1"},{"container_dir":"dir2","device_type":"type2","mode":"mode2"}]')
222222
end
223223

@@ -229,7 +229,7 @@ module VCAP::CloudController::Diego
229229
include_examples 'mapping of credentials'
230230

231231
include_examples 'expected files',
232-
%w[type provider label binding-guid name binding-name instance-guid instance-name plan tags string number boolean array hash volume-mounts]
232+
%w[type provider label binding_guid name binding_name instance_guid instance_name plan tags string number boolean array hash volume_mounts]
233233
end
234234

235235
context 'when the instance is user-provided' do
@@ -241,7 +241,7 @@ module VCAP::CloudController::Diego
241241
include_examples 'mapping of tags', '["an-upsi-tag","another-upsi-tag"]'
242242
include_examples 'mapping of credentials'
243243

244-
include_examples 'expected files', %w[type provider label binding-guid name binding-name instance-guid instance-name tags string number boolean array hash]
244+
include_examples 'expected files', %w[type provider label binding_guid name binding_name instance_guid instance_name tags string number boolean array hash]
245245
end
246246

247247
context 'when there are duplicate keys at different levels' do
@@ -254,7 +254,7 @@ module VCAP::CloudController::Diego
254254
include_examples 'mapping of tags'
255255
include_examples 'mapping of credentials', { credentials: '{"password":"secret"}' }
256256

257-
include_examples 'expected files', %w[type provider label binding-guid name binding-name instance-guid instance-name plan tags credentials]
257+
include_examples 'expected files', %w[type provider label binding_guid name binding_name instance_guid instance_name plan tags credentials]
258258
end
259259

260260
context 'when there are duplicate binding names' do

0 commit comments

Comments
 (0)