Skip to content

Commit

Permalink
Merge pull request #2393 from cloudfoundry/bugfix/resurrection-config…
Browse files Browse the repository at this point in the history
…-cached-even-if-deleted

deleted bosh config leaves dangling hm rule
  • Loading branch information
ramonskie authored Aug 3, 2022
2 parents 75c9d6b + a795200 commit dd09005
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bosh-monitor/lib/bosh/monitor/resurrection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ def resurrection_enabled?(deployment_name, instance_group)
end

def update_rules(resurrection_configs)
return if resurrection_configs.nil?

new_parsed_rules = []
return if resurrection_configs.nil? || resurrection_configs.empty?

resurrection_config_sha = resurrection_configs.map do |resurrection_config|
Digest::SHA256.digest(resurrection_config['content'])
end

if @resurrection_config_sha.to_set != resurrection_config_sha.to_set
@logger.info('Resurrection config update starting...')

resurrection_rule_hashes = resurrection_configs.map do |resurrection_config|
YAML.safe_load(resurrection_config['content'])['rules']
end.flatten || []

resurrection_rule_hashes.each do |resurrection_rule_hash|
new_parsed_rules << ResurrectionRule.parse(resurrection_rule_hash)
rescue StandardError => e
@logger.error("Failed to parse resurrection config rule #{resurrection_rule_hash.inspect}: #{e.inspect}")
end

@parsed_rules = new_parsed_rules
@resurrection_config_sha = resurrection_config_sha
@logger.info('Resurrection config update finished')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ module Bhm
expect(resurrection_rules[1].enabled?).to be_falsey
end
end

context 'when resurrection config is an empty array' do
it 'deletes existing resurrection rules' do
manager.update_rules(resurrection_config)
expect(logger).to receive(:info).with('Resurrection config update starting...')
expect(logger).to receive(:info).with('Resurrection config update finished')
manager.update_rules([])
resurrection_rules = manager.instance_variable_get(:@parsed_rules)
expect(resurrection_rules.count).to eq(0)
end
end

context 'when resurrection config is nil' do
it 'uses existing resurrection rules' do
expect(logger).to receive(:info).with('Resurrection config update starting...')
expect(logger).to receive(:info).with('Resurrection config update finished')
manager.update_rules(resurrection_config)

manager.update_rules(nil)
resurrection_rules = manager.instance_variable_get(:@parsed_rules)
expect(resurrection_rules.count).to eq(2)
expect(resurrection_rules[0].enabled?).to be_truthy
expect(resurrection_rules[1].enabled?).to be_falsey
end
end
end

describe '#resurrection_enabled?' do
Expand Down

0 comments on commit dd09005

Please sign in to comment.