From 15a8a9c7e2f63f405e729cc3d32dc236bb1440bc Mon Sep 17 00:00:00 2001 From: Philipp Thun Date: Fri, 25 Oct 2024 11:00:22 +0200 Subject: [PATCH] Use ServiceBindingFilesBuilder in recipe builders - AppRecipeBuilder -> Diego::Bbs::Models::DesiredLRP - TaskRecipeBuilder -> Diego::Bbs::Models::TaskDefinition --- .../diego/app_recipe_builder.rb | 4 ++- .../diego/task_recipe_builder.rb | 7 ++-- .../diego/app_recipe_builder_spec.rb | 15 +++++++++ .../diego/task_recipe_builder_spec.rb | 32 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/lib/cloud_controller/diego/app_recipe_builder.rb b/lib/cloud_controller/diego/app_recipe_builder.rb index 46ce619baa6..97161260c3b 100644 --- a/lib/cloud_controller/diego/app_recipe_builder.rb +++ b/lib/cloud_controller/diego/app_recipe_builder.rb @@ -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' @@ -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 diff --git a/lib/cloud_controller/diego/task_recipe_builder.rb b/lib/cloud_controller/diego/task_recipe_builder.rb index 3b6a5527430..4395d6d0b96 100644 --- a/lib/cloud_controller/diego/task_recipe_builder.rb +++ b/lib/cloud_controller/diego/task_recipe_builder.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb b/spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb index bb7366609f8..59ed02432cb 100644 --- a/spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb +++ b/spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb @@ -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 @@ -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 diff --git a/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb b/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb index b547a76cad0..854864171ce 100644 --- a/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb +++ b/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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