Skip to content

Commit a6118d1

Browse files
committed
GH-130 Fix overwrite of user config data
Users may have their own config data specified for the PE Master group. This commit ensures that when peadm enforces node group configuration including config data on the PE Master group, it merges required config into existing user data to avoid configuration loss.
1 parent 58948cc commit a6118d1

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

Diff for: CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# PEADM module
22

3+
## 2.4.2
4+
### Summary
5+
6+
Bugfix release
7+
8+
### Bugfixes
9+
10+
- Previously, on upgrade, peadm could overwrite user configuration data on the PE Master group because it overwrote the entire configuration data value. This release modifies the peadm::setup::node\_manager desired state configuration to merge required configuration into any existing configuration when configuring data on the PE Master node group.
11+
312
## 2.4.1
413
### Summary
514

Diff for: lib/puppet/functions/peadm/merge_ng_config_data.rb

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# This function takes the name of a Node Group and a config data hash,
5+
# returning the merge of the node group's current config data and the new
6+
# information specified. It is intended to be used in conjunction with
7+
# Deferred().
8+
#
9+
# @return
10+
# Hash
11+
#
12+
# @example
13+
# $data = Deferred('peadm::merge_ng_config_data', ['PE Master', $new_config_data])
14+
#
15+
Puppet::Functions.create_function(:'autope::merge_ng_config_data') do
16+
dispatch :merge_ng_config_data do
17+
param 'String', :group_name
18+
param 'Hash', :new_config_data
19+
end
20+
21+
def merge_ng_config_data(group_name, new_config_data)
22+
require_libs
23+
ensure_config
24+
25+
ng = Puppet::Util::Nc_https.new
26+
group = ng.get_groups.select { |g| g['name'] == group_name }.first
27+
group['config_data'].deep_merge(new_config_data)
28+
rescue StandardError => e
29+
Puppet.warn "Error attempting to read and merge node_group config data for #{group_name}: #{e.message}"
30+
new_config_data
31+
end
32+
33+
def require_libs
34+
require 'deep_merge'
35+
36+
# We are using utilities from the node_manager module. Load 'em up, trying
37+
# hard to get at them even if simple requires don't seem to be working.
38+
begin
39+
require 'puppet/util/nc_https'
40+
require 'puppet_x/node_manager/common'
41+
rescue LoadError
42+
mod = Puppet::Module.find('node_manager', Puppet[:environment].to_s)
43+
require File.join mod.path, 'lib/puppet/util/nc_https'
44+
require File.join mod.path, 'lib/puppet_x/node_manager/common'
45+
end
46+
end
47+
48+
def ensure_config
49+
# Because of failings in the node_manager module, we have to do some jerry
50+
# rigging to ensure this will work when running over `bolt apply`.
51+
return if File.exist?("#{Puppet.settings['confdir']}/node_manager.yaml") ||
52+
!File.exist?('/etc/puppetlabs/puppet/classifier.yaml')
53+
54+
config = YAML.load_file('/etc/puppetlabs/puppet/classifier.yaml').first
55+
config['port'] = 4433
56+
config['hostcert'] = "/etc/puppetlabs/puppet/ssl/certs/#{config['server']}.pem"
57+
config['hostprivkey'] = "/etc/puppetlabs/puppet/ssl/private_keys/#{config['server']}.pem"
58+
config['localcacert'] = '/etc/puppetlabs/puppet/ssl/certs/ca.pem'
59+
File.open("#{Puppet.settings['confdir']}/node_manager.yaml", 'w') { |f| f.write(config.to_yaml) }
60+
end
61+
end

Diff for: manifests/setup/node_manager.pp

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
# out-of-box configuration of the group.
6363
$compiler_pool_address_data = $compiler_pool_address ? {
6464
undef => undef,
65-
default => { 'pe_repo' => { 'compile_master_pool_address' => $compiler_pool_address } },
65+
default => Deferred('peadm::merge_ng_config_data', ['PE Master',
66+
{ 'pe_repo' => { 'compile_master_pool_address' => $compiler_pool_address } }
67+
]),
6668
}
6769

6870
node_group { 'PE Master':

0 commit comments

Comments
 (0)