Skip to content

Commit

Permalink
Use ServiceBindingFilesBuilder in recipe builders
Browse files Browse the repository at this point in the history
- AppRecipeBuilder -> Diego::Bbs::Models::DesiredLRP
- TaskRecipeBuilder -> Diego::Bbs::Models::TaskDefinition
  • Loading branch information
philippthun committed Nov 27, 2024
1 parent 3cd5c42 commit 15a8a9c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/cloud_controller/diego/app_recipe_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'cloud_controller/diego/cnb/desired_lrp_builder'
require 'cloud_controller/diego/process_guid'
require 'cloud_controller/diego/ssh_key'
require 'cloud_controller/diego/service_binding_files_builder'
require 'credhub/config_helpers'
require 'models/helpers/health_check_types'
require 'cloud_controller/diego/main_lrp_action_builder'
Expand Down Expand Up @@ -100,7 +101,8 @@ def app_lrp_arguments
organizational_unit: ["organization:#{process.organization.guid}", "space:#{process.space.guid}", "app:#{process.app_guid}"]
),
image_username: process.desired_droplet.docker_receipt_username,
image_password: process.desired_droplet.docker_receipt_password
image_password: process.desired_droplet.docker_receipt_password,
volume_mounted_files: ServiceBindingFilesBuilder.build(process)
}.compact
end

Expand Down
7 changes: 5 additions & 2 deletions lib/cloud_controller/diego/task_recipe_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'cloud_controller/diego/bbs_environment_builder'
require 'cloud_controller/diego/task_completion_callback_generator'
require 'cloud_controller/diego/task_cpu_weight_calculator'
require 'cloud_controller/diego/service_binding_files_builder'

module VCAP::CloudController
module Diego
Expand Down Expand Up @@ -52,7 +53,8 @@ def build_app_task(config, task)
]
),
image_username: task.droplet.docker_receipt_username,
image_password: task.droplet.docker_receipt_password
image_password: task.droplet.docker_receipt_password,
volume_mounted_files: ServiceBindingFilesBuilder.build(task.app)
}.compact)
end

Expand Down Expand Up @@ -90,7 +92,8 @@ def build_staging_task(config, staging_details)
]
),
image_username: staging_details.package.docker_username,
image_password: staging_details.package.docker_password
image_password: staging_details.package.docker_password,
volume_mounted_files: ServiceBindingFilesBuilder.build(staging_details.package.app)
}.compact)
end

Expand Down
15 changes: 15 additions & 0 deletions spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module Diego
expect(lrp.trusted_system_certificates_path).to eq(RUNNING_TRUSTED_SYSTEM_CERT_PATH)
expect(lrp.PlacementTags).to eq(['placement-tag'])
expect(lrp.certificate_properties).to eq(expected_certificate_properties)

expect(lrp.volume_mounted_files).to be_empty
end
end

Expand Down Expand Up @@ -914,6 +916,19 @@ module Diego
expect(lrp2.action).to eq(expected_action)
end
end

context 'when file-based service bindings are enabled' do
before do
app = process.app
app.update(file_based_service_bindings_enabled: true)
VCAP::CloudController::ServiceBinding.make(service_instance: ManagedServiceInstance.make(space: app.space), app: app)
end

it 'includes volume mounted files' do
lrp = builder.build_app_lrp
expect(lrp.volume_mounted_files).not_to be_empty
end
end
end

context 'when the lifecycle_type is "cnb"' do
Expand Down
32 changes: 32 additions & 0 deletions spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ module Diego
expect(result.placement_tags).to eq(['potato-segment'])
expect(result.max_pids).to eq(100)
expect(result.certificate_properties).to eq(certificate_properties)

expect(result.volume_mounted_files).to be_empty
end

it 'gives the task a TrustedSystemCertificatesPath' do
Expand All @@ -198,6 +200,19 @@ module Diego
expect(result.placement_tags).to eq([])
end
end

context 'when file-based service bindings are enabled' do
before do
app = staging_details.package.app
app.update(file_based_service_bindings_enabled: true)
VCAP::CloudController::ServiceBinding.make(service_instance: ManagedServiceInstance.make(space: app.space), app: app)
end

it 'includes volume mounted files' do
result = task_recipe_builder.build_staging_task(config, staging_details)
expect(result.volume_mounted_files).not_to be_empty
end
end
end

context 'with a docker backend' do
Expand Down Expand Up @@ -505,6 +520,8 @@ module Diego
expect(result.metric_tags['organization_name'].static).to eq('MyOrg')
expect(result.metric_tags['space_name'].static).to eq('MySpace')
expect(result.metric_tags['app_name'].static).to eq('MyApp')

expect(result.volume_mounted_files).to be_empty
end

context 'when a volume mount is provided' do
Expand Down Expand Up @@ -583,6 +600,19 @@ module Diego
expect(result.placement_tags).to eq([])
end
end

context 'when file-based service bindings are enabled' do
before do
app = task.app
app.update(file_based_service_bindings_enabled: true)
VCAP::CloudController::ServiceBinding.make(service_instance: ManagedServiceInstance.make(space: app.space), app: app)
end

it 'includes volume mounted files' do
result = task_recipe_builder.build_app_task(config, task)
expect(result.volume_mounted_files).not_to be_empty
end
end
end

context 'with a docker backend' do
Expand Down Expand Up @@ -658,6 +688,8 @@ module Diego

expect(result.image_username).to eq('dockerusername')
expect(result.image_password).to eq('dockerpassword')

expect(result.volume_mounted_files).to be_empty
end

context 'when a volume mount is provided' do
Expand Down

0 comments on commit 15a8a9c

Please sign in to comment.