Skip to content

Commit 713565d

Browse files
committed
Adding support for legacy compilers
1 parent e59df9d commit 713565d

File tree

10 files changed

+328
-2
lines changed

10 files changed

+328
-2
lines changed

Diff for: .github/workflows/test-upgrade-legacy.yaml

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
name: "Upgrade PE with one legacy compiler"
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- ".github/workflows/**/*"
8+
- "spec/**/*"
9+
- "lib/**/*"
10+
- "tasks/**/*"
11+
- "functions/**/*"
12+
- "types/**/*"
13+
- "plans/**/*"
14+
- "hiera/**/*"
15+
- "manifests/**/*"
16+
- "templates/**/*"
17+
- "files/**/*"
18+
- "metadata.json"
19+
- "Rakefile"
20+
- "Gemfile"
21+
- "provision.yaml"
22+
- ".rspec"
23+
- ".rubocop.yml"
24+
- ".puppet-lint.rc"
25+
- ".fixtures.yml"
26+
branches: [main]
27+
workflow_dispatch:
28+
ssh-debugging:
29+
description: "Boolean; whether or not to pause for ssh debugging"
30+
required: true
31+
default: "false"
32+
33+
jobs:
34+
test-install:
35+
name: "PE ${{ matrix.version }} ${{ matrix.architecture }} on ${{ matrix.image }}"
36+
runs-on: ubuntu-20.04
37+
env:
38+
BOLT_GEM: true
39+
BOLT_DISABLE_ANALYTICS: true
40+
LANG: "en_US.UTF-8"
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
architecture:
45+
- "large-with-two-compilers"
46+
image:
47+
- "almalinux-cloud/almalinux-8"
48+
version:
49+
- "2023.6.0"
50+
to_version:
51+
- "2023.7.0"
52+
53+
steps:
54+
- name: "Start SSH session"
55+
if: ${{ github.event.inputs.ssh-debugging == 'true' }}
56+
uses: luchihoratiu/debug-via-ssh@main
57+
with:
58+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
59+
SSH_PASS: ${{ secrets.SSH_PASS }}
60+
61+
- name: "Checkout Source"
62+
uses: actions/checkout@v2
63+
64+
- name: "Activate Ruby 2.7"
65+
uses: ruby/setup-ruby@v1
66+
with:
67+
ruby-version: "2.7"
68+
bundler-cache: true
69+
70+
- name: "Print bundle environment"
71+
if: ${{ github.repository_owner == 'puppetlabs' }}
72+
run: |
73+
echo ::group::info:bundler
74+
bundle env
75+
echo ::endgroup::
76+
77+
- name: "Provision test cluster"
78+
timeout-minutes: 15
79+
run: |
80+
echo ::group::prepare
81+
mkdir -p $HOME/.ssh
82+
echo 'Host *' > $HOME/.ssh/config
83+
echo ' ServerAliveInterval 150' >> $HOME/.ssh/config
84+
echo ' ServerAliveCountMax 2' >> $HOME/.ssh/config
85+
bundle exec rake spec_prep
86+
echo ::endgroup::
87+
88+
echo ::group::provision
89+
bundle exec bolt plan run peadm_spec::provision_test_cluster \
90+
--modulepath spec/fixtures/modules \
91+
provider=provision_service \
92+
image=${{ matrix.image }} \
93+
architecture=${{ matrix.architecture }}
94+
echo ::endgroup::
95+
96+
echo ::group::info:request
97+
cat request.json || true; echo
98+
echo ::endgroup::
99+
100+
echo ::group::info:inventory
101+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
102+
echo ::endgroup::
103+
104+
- name: Set up yq
105+
uses: frenck/action-setup-yq@v1
106+
with:
107+
version: v4.30.5
108+
109+
- name: 'Install PE on test cluster'
110+
timeout-minutes: 120
111+
run: |
112+
bundle exec bolt plan run peadm_spec::install_test_cluster \
113+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
114+
--modulepath spec/fixtures/modules \
115+
architecture="large" \
116+
version=${{ matrix.version }}
117+
118+
- name: 'Wait as long as the file ${HOME}/pause file is present'
119+
if: ${{ always() && github.event.inputs.ssh-debugging == 'true' }}
120+
run: |
121+
while [ -f "${HOME}/pause" ] ; do
122+
echo "${HOME}/pause present, sleeping for 60 seconds..."
123+
sleep 60
124+
done
125+
echo "${HOME}/pause absent, continuing workflow."
126+
127+
- name: 'Convert one compiler to legacy'
128+
timeout-minutes: 120
129+
run: |
130+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .uri' spec/fixtures/litmus_inventory.yaml)
131+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .uri' spec/fixtures/litmus_inventory.yaml | head -n 1)
132+
133+
bundle exec bolt plan run peadm::convert_compiler_to_legacy \
134+
--modulepath spec/fixtures/modules \
135+
primary_host=$primary \
136+
compiler_hosts=$compiler
137+
138+
139+
- name: 'Upgrade PE on test cluster'
140+
timeout-minutes: 120
141+
run: |
142+
bundle exec bolt plan run peadm_spec::upgrade_test_cluster \
143+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
144+
--modulepath spec/fixtures/modules \
145+
architecture="large" \
146+
version=${{ matrix.to_version }}
147+
148+
- name: "Tear down test cluster"
149+
if: ${{ always() }}
150+
continue-on-error: true
151+
run: |
152+
if [ -f spec/fixtures/litmus_inventory.yaml ]; then
153+
echo ::group::tear_down
154+
bundle exec rake 'litmus:tear_down'
155+
echo ::endgroup::
156+
157+
echo ::group::info:request
158+
cat request.json || true; echo
159+
echo ::endgroup::
160+
fi

Diff for: functions/oid.pp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function peadm::oid (
44
case $short_name {
55
'peadm_role': { '1.3.6.1.4.1.34380.1.1.9812' }
66
'peadm_availability_group': { '1.3.6.1.4.1.34380.1.1.9813' }
7+
'peadm_legacy_compiler': { '1.3.6.1.4.1.34380.1.1.9814' }
78
'pp_application': { '1.3.6.1.4.1.34380.1.1.8' }
89
'pp_cluster': { '1.3.6.1.4.1.34380.1.1.16' }
910
'pp_role': { '1.3.6.1.4.1.34380.1.1.13' }

Diff for: manifests/setup/legacy_compiler_group.pp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# @api private
2+
class peadm::setup::legacy_compiler_group (
3+
String[1] $primary_host
4+
) {
5+
Node_group {
6+
purge_behavior => none,
7+
}
8+
9+
node_group { 'PE Legacy Compiler':
10+
parent => 'PE Master',
11+
rule => ['and',
12+
['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'true'],
13+
['=', ['trusted', 'extensions', 'pp_auth_role'], 'pe_compiler'],
14+
],
15+
classes => {
16+
'pe_repo' => {},
17+
'puppet_enterprise::profile::master' => { 'code_manager_auto_configure' => true, 'replication_mode' => 'none' },
18+
},
19+
data => {
20+
'pe_repo' => { 'compile_master_pool_address' => $primary_host },
21+
},
22+
variables => {
23+
'pe_master' => true,
24+
},
25+
}
26+
27+
node_group { 'PE Compiler':
28+
rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']],
29+
}
30+
}

Diff for: manifests/setup/node_manager.pp

+24
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
variables => { 'pe_master' => true },
7979
}
8080

81+
# PE Compiler group comes from default PE and already has the pe compiler role
82+
node_group { 'PE Compiler':
83+
parent => 'PE Master',
84+
rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']],
85+
}
86+
8187
# This group should pin the primary, and also map to any pe-postgresql nodes
8288
# which are part of the architecture.
8389
node_group { 'PE Database':
@@ -191,4 +197,22 @@
191197
},
192198
},
193199
}
200+
201+
node_group { 'PE Legacy Compiler':
202+
parent => 'PE Master',
203+
rule => ['and',
204+
['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'true'],
205+
['=', ['trusted', 'extensions', 'pp_auth_role'], 'pe_compiler'],
206+
],
207+
classes => {
208+
'pe_repo' => {},
209+
'puppet_enterprise::profile::master' => { 'code_manager_auto_configure' => true, 'replication_mode' => 'none' },
210+
},
211+
data => {
212+
'pe_repo' => { 'compile_master_pool_address' => $primary_host },
213+
},
214+
variables => {
215+
'pe_master' => true,
216+
},
217+
}
194218
}

Diff for: plans/convert_compiler_to_legacy.pp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# @api private
2+
plan peadm::convert_compiler_to_legacy (
3+
Peadm::SingleTargetSpec $primary_host,
4+
TargetSpec $legacy_hosts,
5+
Boolean $remove_pdb = false,
6+
) {
7+
$primary_target = peadm::get_targets($primary_host, 1)
8+
$legacy_targets = peadm::get_targets($legacy_hosts)
9+
10+
$cluster = run_task('peadm::get_peadm_config', $primary_host).first.value
11+
$error = getvar('cluster.error')
12+
if $error {
13+
fail_plan($error)
14+
}
15+
16+
$all_targets = peadm::flatten_compact([
17+
getvar('cluster.params.primary_host'),
18+
getvar('cluster.params.replica_host'),
19+
getvar('cluster.params.primary_postgresql_host'),
20+
getvar('cluster.params.replica_postgresql_host'),
21+
getvar('cluster.params.compiler_hosts'),
22+
])
23+
24+
if $remove_pdb {
25+
run_command('puppet resource service puppet ensure=stopped', $legacy_targets)
26+
run_command('puppet resource service pe-puppetdb ensure=stopped enable=false', $legacy_targets)
27+
}
28+
29+
apply($primary_target) {
30+
class { 'peadm::setup::node_manager_yaml':
31+
primary_host => $primary_target.peadm::certname(),
32+
}
33+
34+
class { 'peadm::setup::legacy_compiler_group':
35+
primary_host => $primary_target.peadm::certname(),
36+
}
37+
}
38+
39+
run_plan('peadm::update_compiler_extensions', compiler_hosts => $legacy_targets, primary_host => $primary_target, legacy => true)
40+
41+
run_task('peadm::puppet_runonce', $legacy_targets)
42+
run_task('peadm::puppet_runonce', $primary_target)
43+
run_task('peadm::puppet_runonce', $all_targets)
44+
45+
if $remove_pdb {
46+
run_command('puppet resource package pe-puppetdb ensure=purged', $legacy_targets)
47+
run_command('puppet resource user pe-puppetdb ensure=absent', $legacy_targets)
48+
49+
run_command('rm -rf /etc/puppetlabs/puppetdb', $legacy_targets)
50+
run_command('rm -rf /var/log/puppetlabs/puppetdb', $legacy_targets)
51+
run_command('rm -rf /opt/puppetlabs/server/data/puppetdb', $legacy_targets)
52+
}
53+
54+
run_command('systemctl start pe-puppetserver.service', $legacy_targets)
55+
run_command('puppet resource service puppet ensure=running', $legacy_targets)
56+
57+
return("Converted host ${legacy_targets} to legacy compiler.")
58+
}

Diff for: plans/subplans/component_install.pp

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
peadm::oid('pp_auth_role') => 'pe_compiler',
2323
peadm::oid('peadm_availability_group') => $avail_group_letter,
2424
}
25+
} elsif $role == 'pe_compiler_legacy' {
26+
$certificate_extensions = {
27+
peadm::oid('peadm_role') => $role,
28+
}
2529
} else {
2630
$certificate_extensions = {
2731
peadm::oid('peadm_role') => $role,

Diff for: plans/subplans/install.pp

+2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
extension_requests => {
279279
peadm::oid('pp_auth_role') => 'pe_compiler',
280280
peadm::oid('peadm_availability_group') => 'A',
281+
peadm::oid('peadm_legacy_compiler') => 'false',
281282
}
282283
)
283284
},
@@ -286,6 +287,7 @@
286287
extension_requests => {
287288
peadm::oid('pp_auth_role') => 'pe_compiler',
288289
peadm::oid('peadm_availability_group') => 'B',
290+
peadm::oid('peadm_legacy_compiler') => 'false',
289291
}
290292
)
291293
},

Diff for: plans/update_compiler_extensions.pp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# @api private
2+
plan peadm::update_compiler_extensions (
3+
TargetSpec $compiler_hosts,
4+
Peadm::SingleTargetSpec $primary_host,
5+
Boolean $legacy = false,
6+
) {
7+
$primary_target = peadm::get_targets($primary_host, 1)
8+
$host_targets = peadm::get_targets($compiler_hosts)
9+
10+
run_plan('peadm::modify_certificate', $host_targets,
11+
primary_host => $primary_target,
12+
add_extensions => {
13+
peadm::oid('peadm_legacy_compiler') => "${legacy}",
14+
},
15+
)
16+
17+
run_task('peadm::puppet_runonce', $primary_target)
18+
run_task('peadm::puppet_runonce', $host_targets)
19+
20+
if $legacy {
21+
run_command('systemctl restart pe-puppetserver.service', $host_targets)
22+
} else {
23+
run_command('systemctl restart pe-puppetserver.service pe-puppetdb.service', $host_targets)
24+
}
25+
26+
return("Added legacy cert with value ${legacy} to compiler hosts ${compiler_hosts}")
27+
}

0 commit comments

Comments
 (0)