Skip to content

Commit

Permalink
Broker accepts many ServiceDeployment.Stemcells
Browse files Browse the repository at this point in the history
- service_deployment.stemcell is no more

[#164954639]

Co-authored-by: Diego Lemos <[email protected]>
Co-authored-by: Winna Bridgewater <[email protected]>
  • Loading branch information
3 people committed Mar 28, 2019
1 parent 30ad0da commit e06f172
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 28 deletions.
6 changes: 3 additions & 3 deletions examples/deployment/operations/kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
- name: ((service_release))
version: ((service_release_version))
jobs: [kafka_server, zookeeper_server]
stemcell:
os: ((meta.stemcell.os))
version: "((meta.stemcell.version))"
stemcells:
- os: ((meta.stemcell.os))
version: "((meta.stemcell.version))"

- type: replace
path: /instance_groups/name=broker/jobs/-
Expand Down
5 changes: 3 additions & 2 deletions examples/deployment/operations/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
- name: ((service_release))
version: ((service_release_version))
jobs: [redis-server, health-check, cleanup-data]
stemcell:
os: ((meta.stemcell.os))
stemcells:
- os: ((meta.stemcell.os))
version: "((meta.stemcell.version))"
alias: default

- type: replace
path: /instance_groups/name=broker/jobs/-
Expand Down
7 changes: 7 additions & 0 deletions jobs/broker/spec
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ properties:
service_deployment.releases:
description: releases to deploy for each instance

service_deployment.stemcells:
description: stemcells to deploy for each instance
default: []
example:
- os: ubuntu
version: 1234

service_deployment.stemcell.os:
description: stemcell OS to use for every job in the service deployment

Expand Down
33 changes: 28 additions & 5 deletions jobs/broker/templates/broker.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,33 @@ def validate_releases(service_deployment)
end
end

def validate_stemcell(service_deployment)
def prepare_stemcells(service_deployment)
legacy_stemcell = service_deployment['stemcell']
legacy_os = service_deployment['stemcell']['os'] || nil # nil
legacy_version = service_deployment['stemcell']['version'] || nil # 12334

if !service_deployment['stemcells'].empty? && !legacy_os.nil? && !legacy_version.nil? then
raise 'You cannot configure both "stemcell" and "stemcells" in broker.service_deployment.'
end

if !legacy_os.nil? || !legacy_version.nil? then
service_deployment['stemcells'] << legacy_stemcell
end
service_deployment['stemcell'] = nil

if service_deployment['stemcells'].empty? then
raise 'Invalid service_deployment config - at least one stemcell must be specified'
end

service_deployment['stemcells'].each do |stemcell|
validate_stemcell stemcell
end
end

def validate_stemcell(stemcell)
required_stemcell_keys = %w{os version}
validate_config(service_deployment['stemcell'], required_stemcell_keys, "Invalid service_deployment.stemcell config - must specify ")
if service_deployment['stemcell']['version'] =~ /latest$/
validate_config(stemcell, required_stemcell_keys, "Invalid service_deployment stemcell config - must specify ")
if stemcell['version'] =~ /latest$/
raise "You must configure the exact release and stemcell versions in broker.service_deployment. " +
"ODB requires exact versions to detect pending changes as part of the 'cf update-service' workflow. For example, latest and 3112.latest are not supported."
end
Expand Down Expand Up @@ -151,7 +174,7 @@ end

service_deployment = p('service_deployment')
validate_releases(service_deployment)
validate_stemcell(service_deployment)
prepare_stemcells(service_deployment)

if p('disable_cf_startup_checks')
global_limit = service_catalog.dig('global_quotas', 'service_instance_limit')
Expand Down Expand Up @@ -346,7 +369,7 @@ config = {
"bosh" => bosh_config,
"cf" => cf_config,
"service_adapter" => p('service_adapter'),
"service_deployment" => p('service_deployment'),
"service_deployment" => service_deployment,
"service_catalog" => service_catalog,
"bosh_credhub" => p('bosh_credhub_api')
}.merge(credhub_config).merge(service_instances_api_config)
Expand Down
118 changes: 107 additions & 11 deletions spec/broker_config_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -808,33 +808,129 @@
end
end

context 'when no stemcell os is configured' do
describe '"stemcells" property' do
let(:manifest_file) { File.open 'spec/fixtures/valid-mandatory-broker-config.yml' }

it "is included in the configuration" do
obj = YAML.load(rendered_template)
expect(obj['service_deployment']['stemcells']).to eq([{"os"=>"ubuntu-trusty", "version"=>1234, "alias"=>"default"}])
end

context 'when "stemcell" is also configured' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell'] = {
'os' => 'ubuntu-trusty','version' => 1234
}
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'You cannot configure both "stemcell" and "stemcells" in broker.service_deployment.')
)
end
end

context 'when one of the stemcells does not configure OS' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'][0]['os'] = nil
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment stemcell config - must specify os')
)
end
end

context 'when one of the stemcells does not configure version' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'][0]['version'] = nil
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment stemcell config - must specify version')
)
end
end
end

context 'when neither "stemcell" nor "stemcells" is configured' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell']['os'] = nil
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'] = nil
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment.stemcell config - must specify os')
raise_error(RuntimeError, 'Invalid service_deployment config - at least one stemcell must be specified')
)
end
end

context 'when no stemcell version is configured' do
describe 'deprecated "stemcell" property' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell']['version'] = nil
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'] = []
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell'] = {
'os' => 'ubuntu-trusty', 'version' => 2311
}
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment.stemcell config - must specify version')
)

it 'generates the config with "stemcells"' do
obj = YAML.load(rendered_template)
expect(obj['service_deployment']['stemcells']).to eq([{"os"=>"ubuntu-trusty", "version"=>2311}])
expect(obj['service_deployment']['stemcell']).to be_nil
end

context 'when no stemcell os is configured' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'] = []
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell'] = {
'os' => nil, 'version' => 2311
}
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment stemcell config - must specify os')
)
end
end

context 'when no stemcell version is configured' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'] = []
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell'] = {
'os' => 'ubuntu-xenial', 'version' => nil
}
yaml
end
end

it 'raises an error' do
expect { rendered_template }.to(
raise_error(RuntimeError, 'Invalid service_deployment stemcell config - must specify version')
)
end
end
end

Expand Down Expand Up @@ -873,7 +969,7 @@
context 'when a stemcell version is latest' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell']['version'] = 'latest'
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'] = [{'version' => 'latest', 'os' => 'ubuntu-trusty'}]
yaml
end
end
Expand All @@ -889,7 +985,7 @@
context 'when a stemcell version is n.latest' do
let(:manifest_file) do
generate_test_manifest do |yaml|
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcell']['version'] = '22.latest'
yaml['instance_groups'][0]['jobs'][0]['properties']['service_deployment']['stemcells'][0]['version'] = '22.latest'
yaml
end
end
Expand Down
7 changes: 4 additions & 3 deletions spec/fixtures/valid-mandatory-broker-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ instance_groups:
- name: a-release
version: 1234
jobs: [job-1]
stemcell:
os: ubuntu-trusty
version: 1234
stemcells:
- os: ubuntu-trusty
version: 1234
alias: default
service_catalog:
id: some-id
service_name: some-name
Expand Down

0 comments on commit e06f172

Please sign in to comment.