From 33d7f52f135dee54a87cd491255e59ebb213b0db Mon Sep 17 00:00:00 2001 From: Jochen Ehret Date: Mon, 21 Oct 2024 16:56:17 +0200 Subject: [PATCH 1/2] Remove v2 section from / if temporary_enable_v2 == false * use config paraemter "temporary_enable_v2" from capi-release (default: true) * if false, remove "cloud_controller_v2" section from root endpoint --- app/controllers/runtime/root_controller.rb | 22 +++++++++++++------ config/cloud_controller.yml | 2 ++ .../config_schemas/base/api_schema.rb | 2 ++ .../runtime/root_controller_spec.rb | 12 ++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/controllers/runtime/root_controller.rb b/app/controllers/runtime/root_controller.rb index 789e519e08d..d2a25428b9e 100644 --- a/app/controllers/runtime/root_controller.rb +++ b/app/controllers/runtime/root_controller.rb @@ -15,13 +15,6 @@ def read href: api_url_builder.build_url }, - cloud_controller_v2: { - href: api_url_builder.build_url(path: '/v2'), - meta: { - version: VCAP::CloudController::Constants::API_VERSION - } - }, - cloud_controller_v3: { href: api_url_builder.build_url(path: '/v3'), meta: { @@ -71,6 +64,10 @@ def read } } + if config.get(:temporary_enable_v2) + response[:links].merge!(cloud_controller_v2(api_url_builder)) + end + [200, Oj.dump(response, mode: :compat)] end @@ -91,5 +88,16 @@ def routing_link { href: config.get(:routing_api, :url) } end + + def cloud_controller_v2(api_url_builder) + { cloud_controller_v2: + { + href: api_url_builder.build_url(path: '/v2'), + meta: { + version: VCAP::CloudController::Constants::API_VERSION + } + } + } + end end end diff --git a/config/cloud_controller.yml b/config/cloud_controller.yml index 08d6a4c07dc..9c1e0a819fc 100644 --- a/config/cloud_controller.yml +++ b/config/cloud_controller.yml @@ -279,6 +279,8 @@ rate_limiter_v2_api: global_admin_limit: 20000 reset_interval_in_minutes: 60 +temporary_enable_v2: true + max_concurrent_service_broker_requests: 0 diego: diff --git a/lib/cloud_controller/config_schemas/base/api_schema.rb b/lib/cloud_controller/config_schemas/base/api_schema.rb index ff381aee45c..6bf5e263d89 100644 --- a/lib/cloud_controller/config_schemas/base/api_schema.rb +++ b/lib/cloud_controller/config_schemas/base/api_schema.rb @@ -322,6 +322,8 @@ class ApiSchema < VCAP::Config reset_interval_in_minutes: Integer }, + optional(:temporary_enable_v2) => bool, + allow_app_ssh_access: bool, optional(:external_host) => String, diff --git a/spec/unit/controllers/runtime/root_controller_spec.rb b/spec/unit/controllers/runtime/root_controller_spec.rb index e9417caf4bf..e3a55035126 100644 --- a/spec/unit/controllers/runtime/root_controller_spec.rb +++ b/spec/unit/controllers/runtime/root_controller_spec.rb @@ -26,6 +26,18 @@ module VCAP::CloudController ) end + context 'temporary_enable_v2 is false' do + before do + TestConfig.override(temporary_enable_v2: false) + end + + it 'returns no cloud controller v2 link with metadata' do + get '/' + hash = Oj.load(last_response.body) + expect(hash['links']['cloud_controller_v2']).to be_nil + end + end + it 'returns a cloud controller v3 link with metadata' do get '/' hash = Oj.load(last_response.body) From 9d0911eb7d8dbcfe86ebf0c51f0848700ee5269c Mon Sep 17 00:00:00 2001 From: Jochen Ehret Date: Tue, 22 Oct 2024 10:27:29 +0200 Subject: [PATCH 2/2] Fix Rubocop findings --- app/controllers/runtime/root_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/runtime/root_controller.rb b/app/controllers/runtime/root_controller.rb index d2a25428b9e..d6bc9beebb2 100644 --- a/app/controllers/runtime/root_controller.rb +++ b/app/controllers/runtime/root_controller.rb @@ -64,9 +64,7 @@ def read } } - if config.get(:temporary_enable_v2) - response[:links].merge!(cloud_controller_v2(api_url_builder)) - end + response[:links].merge!(cloud_controller_v2(api_url_builder)) if config.get(:temporary_enable_v2) [200, Oj.dump(response, mode: :compat)] end @@ -90,7 +88,8 @@ def routing_link end def cloud_controller_v2(api_url_builder) - { cloud_controller_v2: + { + cloud_controller_v2: { href: api_url_builder.build_url(path: '/v2'), meta: {