Skip to content

Commit d4ca4ba

Browse files
committed
Read storage-cli config JSON from capi (AzureRM)
Stop building storage-cli JSON inside CC; instead consume files rendered by capi job templates. StorageCliClient now selects the JSON file by `resource_type`.
1 parent 3a98e06 commit d4ca4ba

File tree

11 files changed

+229
-24
lines changed

11 files changed

+229
-24
lines changed

config/cloud_controller.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ directories:
320320
diagnostics: /tmp
321321

322322
stacks_file: config/stacks.yml
323+
324+
storage_cli_config_file_droplets: config/storage_cli_config_droplets.json
325+
storage_cli_config_file_packages: config/storage_cli_config_packages.json
326+
storage_cli_config_file_buildpacks: config/storage_cli_config_buildpacks.json
327+
storage_cli_config_file_resource_pool: config/storage_cli_config_resource_pool.json
328+
323329
newrelic_enabled: false
324330

325331
max_annotations_per_resource: 200

lib/cloud_controller/blobstore/client_provider.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def self.provide(options:, directory_key:, root_dir: nil, resource_type: nil)
1616
provide_fog(options, directory_key, root_dir)
1717
elsif options[:blobstore_type] == 'storage-cli'
1818
# storage-cli is an experimental feature and not yet fully implemented. !!! DO NOT USE IN PRODUCTION !!!
19-
provide_storage_cli(options, directory_key, root_dir)
19+
provide_storage_cli(options, directory_key, root_dir, resource_type)
2020
else
2121
provide_webdav(options, directory_key, root_dir)
2222
end
@@ -71,11 +71,12 @@ def provide_webdav(options, directory_key, root_dir)
7171
Client.new(SafeDeleteClient.new(retryable_client, root_dir))
7272
end
7373

74-
def provide_storage_cli(options, directory_key, root_dir)
74+
def provide_storage_cli(options, directory_key, root_dir, resource_type)
7575
raise BlobstoreError.new('connection_config for storage-cli is not provided') unless options[:connection_config]
7676

7777
client = StorageCliClient.build(connection_config: options.fetch(:connection_config),
7878
directory_key: directory_key,
79+
resource_type: resource_type,
7980
root_dir: root_dir,
8081
min_size: options[:minimum_size],
8182
max_size: options[:maximum_size])

lib/cloud_controller/blobstore/storage_cli/azure_storage_cli_client.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ def cli_path
55
ENV['AZURE_STORAGE_CLI_PATH'] || '/var/vcap/packages/azure-storage-cli/bin/azure-storage-cli'
66
end
77

8-
def build_config(connection_config)
9-
{
10-
account_name: connection_config[:azure_storage_account_name],
11-
account_key: connection_config[:azure_storage_access_key],
12-
container_name: @directory_key,
13-
environment: connection_config[:environment]
14-
}.compact
15-
end
16-
178
CloudController::Blobstore::StorageCliClient.register('AzureRM', AzureStorageCliClient)
189
end
1910
end

lib/cloud_controller/blobstore/storage_cli/storage_cli_client.rb

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,53 @@ def register(provider, klass)
1919
registry[provider] = klass
2020
end
2121

22-
def build(connection_config:, directory_key:, root_dir:, min_size: nil, max_size: nil)
22+
def build(connection_config:, directory_key:, root_dir:, resource_type: nil, min_size: nil, max_size: nil)
2323
provider = connection_config[:provider]
2424
raise 'Missing connection_config[:provider]' if provider.nil?
25+
raise 'Missing resource_type' if resource_type.nil?
2526

2627
impl_class = registry[provider]
2728
raise "No storage CLI client registered for provider #{provider}" unless impl_class
2829

29-
impl_class.new(connection_config:, directory_key:, root_dir:, min_size:, max_size:)
30+
impl_class.new(connection_config:, directory_key:, root_dir:, resource_type:, min_size:, max_size:)
3031
end
3132
end
3233

33-
def initialize(connection_config:, directory_key:, root_dir:, min_size: nil, max_size: nil)
34+
def initialize(connection_config:, directory_key:, resource_type:, root_dir:, min_size: nil, max_size: nil)
3435
@cli_path = cli_path
3536
@directory_key = directory_key
37+
@resource_type = resource_type.to_s
3638
@root_dir = root_dir
3739
@min_size = min_size || 0
3840
@max_size = max_size
39-
config = build_config(connection_config)
40-
@config_file = write_config_file(config)
4141
@fork = connection_config.fetch(:fork, false)
42+
43+
file_path = case @resource_type
44+
when 'droplets', 'buildpack_cache'
45+
VCAP::CloudController::Config.config.get(:storage_cli_config_file_droplets)
46+
when 'buildpacks'
47+
VCAP::CloudController::Config.config.get(:storage_cli_config_file_buildpacks)
48+
when 'packages'
49+
VCAP::CloudController::Config.config.get(:storage_cli_config_file_packages)
50+
when 'resource_pool'
51+
VCAP::CloudController::Config.config.get(:storage_cli_config_file_resource_pool)
52+
else
53+
raise BlobstoreError.new("Unknown resource_type: #{@resource_type}")
54+
end
55+
56+
unless file_path && File.file?(file_path) && File.readable?(file_path)
57+
raise BlobstoreError.new("storage-cli config file not found or not readable at: #{file_path.inspect}")
58+
end
59+
60+
begin
61+
VCAP::CloudController::YAMLConfig.safe_load_file(file_path)
62+
rescue => e
63+
raise BlobstoreError.new("Failed to load storage-cli config at #{file_path}: #{e.message}")
64+
end
65+
66+
@config_file = file_path
67+
logger.info('storage_cli_config_selected', resource_type: @resource_type, path: @config_file)
68+
4269
end
4370

4471
def local?

lib/cloud_controller/config_schemas/api_schema.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ class ApiSchema < VCAP::Config
9595
},
9696

9797
stacks_file: String,
98+
99+
optional(:storage_cli_config_file_buildpacks) => String,
100+
optional(:storage_cli_config_file_packages) => String,
101+
optional(:storage_cli_config_file_resource_pool) => String,
102+
optional(:storage_cli_config_file_droplets) => String,
103+
98104
newrelic_enabled: bool,
99105

100106
optional(:max_migration_duration_in_minutes) => Integer,

lib/cloud_controller/config_schemas/clock_schema.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class ClockSchema < VCAP::Config
5050

5151
pid_filename: String, # Pid filename to use
5252

53+
optional(:storage_cli_config_file_buildpacks) => String,
54+
optional(:storage_cli_config_file_packages) => String,
55+
optional(:storage_cli_config_file_resource_pool) => String,
56+
optional(:storage_cli_config_file_droplets) => String,
57+
5358
newrelic_enabled: bool,
5459

5560
optional(:max_migration_duration_in_minutes) => Integer,

lib/cloud_controller/config_schemas/worker_schema.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class WorkerSchema < VCAP::Config
4141
},
4242

4343
stacks_file: String,
44+
45+
optional(:storage_cli_config_file_buildpacks) => String,
46+
optional(:storage_cli_config_file_packages) => String,
47+
optional(:storage_cli_config_file_resource_pool) => String,
48+
optional(:storage_cli_config_file_droplets) => String,
49+
4450
newrelic_enabled: bool,
4551

4652
optional(:max_migration_duration_in_minutes) => Integer,

lib/cloud_controller/dependency_locator.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def legacy_global_app_bits_cache
167167

168168
Blobstore::ClientProvider.provide(
169169
options: options,
170-
directory_key: options.fetch(:resource_directory_key)
170+
directory_key: options.fetch(:resource_directory_key),
171+
resource_type: :resource_pool
171172
)
172173
end
173174

@@ -177,7 +178,8 @@ def global_app_bits_cache
177178
Blobstore::ClientProvider.provide(
178179
options: options,
179180
directory_key: options.fetch(:resource_directory_key),
180-
root_dir: RESOURCE_POOL_DIR
181+
root_dir: RESOURCE_POOL_DIR,
182+
resource_type: :resource_pool
181183
)
182184
end
183185

lib/cloud_controller/resource_pool.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def initialize(config)
2525
@blobstore = CloudController::Blobstore::ClientProvider.provide(
2626
options: options,
2727
directory_key: options.fetch(:resource_directory_key),
28-
root_dir: CloudController::DependencyLocator::RESOURCE_POOL_DIR
28+
root_dir: CloudController::DependencyLocator::RESOURCE_POOL_DIR,
29+
resource_type: 'resource_pool'
2930
)
3031

3132
@minimum_size = options[:minimum_size] || 0 # TODO: move default into config object?

spec/unit/lib/cloud_controller/blobstore/client_provider_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ module Blobstore
129129
context 'when storage-cli is requested' do
130130
let(:blobstore_type) { 'storage-cli' }
131131
let(:directory_key) { 'some-bucket' }
132+
let(:resource_type) { 'some-resource-type' }
132133
let(:root_dir) { 'some-root-dir' }
133134
let(:storage_cli_client_mock) { class_double(CloudController::Blobstore::StorageCliClient) }
134135

@@ -138,8 +139,8 @@ module Blobstore
138139

139140
it 'provides a storage-cli client' do
140141
allow(StorageCliClient).to receive(:build).and_return(storage_cli_client_mock)
141-
ClientProvider.provide(options:, directory_key:, root_dir:)
142-
expect(StorageCliClient).to have_received(:build).with(connection_config: {}, directory_key: directory_key, root_dir: root_dir, min_size: 100, max_size: 1000)
142+
ClientProvider.provide(options:, directory_key:, root_dir:, resource_type:)
143+
expect(StorageCliClient).to have_received(:build).with(connection_config: {}, directory_key: directory_key, resource_type: resource_type, root_dir: root_dir, min_size: 100, max_size: 1000)
143144
end
144145

145146
it 'raises an error if connection_config is not provided' do

0 commit comments

Comments
 (0)