Skip to content

Commit 69cb540

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

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
@@ -44,8 +44,7 @@ def build_service_binding_k8s
4444
sb_hash.delete(:credentials)&.each { |k, v| total_bytesize += add_file(service_binding_files, name, k.to_s, v) }
4545

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

5049
# add the type and provider
5150
label = sb_hash[:label]
@@ -106,14 +105,6 @@ def valid_binding_name?(name)
106105
def valid_file_name?(name)
107106
name.match?(file_naming_convention)
108107
end
109-
110-
def transform_vcap_services_attribute(name)
111-
if %w[binding_guid binding_name instance_guid instance_name syslog_drain_url volume_mounts].include?(name)
112-
name.tr('_', '-')
113-
else
114-
name
115-
end
116-
end
117108
end
118109
end
119110
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,16 +12,16 @@ 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
end
2020

2121
RSpec.shared_examples 'mapping of instance metadata' do |instance_name|
2222
it 'maps service instance metadata attributes to files' do
23-
expect(service_binding_files.find { |f| f.path == "#{directory}/instance-guid" }).to have_attributes(content: instance.guid)
24-
expect(service_binding_files.find { |f| f.path == "#{directory}/instance-name" }).to have_attributes(content: instance_name || 'instance-name')
23+
expect(service_binding_files.find { |f| f.path == "#{directory}/instance_guid" }).to have_attributes(content: instance.guid)
24+
expect(service_binding_files.find { |f| f.path == "#{directory}/instance_name" }).to have_attributes(content: instance_name || 'instance-name')
2525
end
2626
end
2727

@@ -130,7 +130,7 @@ module VCAP::CloudController::Diego
130130
expect(service_binding_files).not_to include(have_attributes(path: 'binding-name/volume_mounts'))
131131
end
132132

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

135135
context 'when binding_name is nil' do
136136
let(:binding_name) { nil }
@@ -143,14 +143,14 @@ module VCAP::CloudController::Diego
143143
include_examples 'mapping of tags'
144144
include_examples 'mapping of credentials'
145145

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

149149
context 'when syslog_drain_url is set' do
150150
let(:syslog_drain_url) { 'https://syslog.drain' }
151151

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

156156
include_examples 'mapping of type and provider'
@@ -161,7 +161,7 @@ module VCAP::CloudController::Diego
161161
include_examples 'mapping of credentials'
162162

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

167167
context 'when volume_mounts is set' do
@@ -181,7 +181,7 @@ module VCAP::CloudController::Diego
181181

182182
it 'maps the attribute to a file' do
183183
expect(service_binding_files.find do |f|
184-
f.path == 'binding-name/volume-mounts'
184+
f.path == 'binding-name/volume_mounts'
185185
end).to have_attributes(content: '[{"container_dir":"dir1","device_type":"type1","mode":"mode1"},{"container_dir":"dir2","device_type":"type2","mode":"mode2"}]')
186186
end
187187

@@ -193,7 +193,7 @@ module VCAP::CloudController::Diego
193193
include_examples 'mapping of credentials'
194194

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

199199
context 'when the instance is user-provided' do
@@ -205,7 +205,7 @@ module VCAP::CloudController::Diego
205205
include_examples 'mapping of tags', '["an-upsi-tag","another-upsi-tag"]'
206206
include_examples 'mapping of credentials'
207207

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

211211
context 'when there are duplicate keys at different levels' do
@@ -218,7 +218,7 @@ module VCAP::CloudController::Diego
218218
include_examples 'mapping of tags'
219219
include_examples 'mapping of credentials', { credentials: '{"password":"secret"}' }
220220

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

224224
context 'when there are duplicate binding names' do

0 commit comments

Comments
 (0)