From 3a4270fcc3c93a313441327005f1d8458f88cff7 Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Mon, 29 Jul 2024 16:27:38 +0100 Subject: [PATCH 1/6] PE-38768 classify compilers plan added --- tasks/classify_compilers.json | 15 +++++++++++ tasks/classify_compilers.rb | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tasks/classify_compilers.json create mode 100644 tasks/classify_compilers.rb diff --git a/tasks/classify_compilers.json b/tasks/classify_compilers.json new file mode 100644 index 00000000..cb85a1dd --- /dev/null +++ b/tasks/classify_compilers.json @@ -0,0 +1,15 @@ +{ + "description": "Classify compilers as legacy or non-legacy", + "parameters": { + "compiler_hosts": { + "type": "Array[String]", + "description": "List of FQDNs of compilers" + } + }, + "implementations": [ + { + "name": "classify_compilers.rb", + "requirements": ["shell"] + } + ] +} \ No newline at end of file diff --git a/tasks/classify_compilers.rb b/tasks/classify_compilers.rb new file mode 100644 index 00000000..e2fc9bd0 --- /dev/null +++ b/tasks/classify_compilers.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +require 'json' +require 'open3' + +def classify_compiler(services) + if services.any? { |service| service['type'] == 'puppetdb' } + :non_legacy + else + :legacy + end +end + +params = JSON.parse(STDIN.read) +compiler_hosts = params['compiler_hosts'] + +legacy_compilers = [] +non_legacy_compilers = [] + +compiler_hosts.each do |compiler| + begin + cmd = "puppet infra status --host #{compiler} --format=json" + stdout, stderr, status = Open3.capture3(cmd) + + if status.success? + services = JSON.parse(stdout) + classification = classify_compiler(services) + + if classification == :legacy + legacy_compilers << compiler + else + non_legacy_compilers << compiler + end + else + STDERR.puts "Error running command for #{compiler}: #{stderr}" + end + rescue => e + STDERR.puts "Error processing #{compiler}: #{e.message}" + end +end + +result = { + 'legacy_compilers' => legacy_compilers, + 'compilers' => non_legacy_compilers +} + +puts result.to_json \ No newline at end of file From ffd760c1611a5c1eed8137c1045f5e45a3892cdb Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Tue, 30 Jul 2024 09:43:45 +0100 Subject: [PATCH 2/6] PE-38768 REFERENCE.md updated --- REFERENCE.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index 76d618c3..e61df4ed 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -56,6 +56,7 @@ * [`backup_classification`](#backup_classification): A task to call the classification api and write to file * [`cert_data`](#cert_data): Return certificate data related to the Puppet agent * [`cert_valid_status`](#cert_valid_status): Check primary for valid state of a certificate +* [`classify_compilers`](#classify_compilers): Classify compilers as legacy or non-legacy * [`code_manager`](#code_manager): Perform various code manager actions * [`code_sync_status`](#code_sync_status): A task to confirm code is in sync accross the cluster for clusters with code manager configured * [`divert_code_manager`](#divert_code_manager): Divert the code manager live-dir setting @@ -1056,6 +1057,20 @@ Data type: `String` The certifcate name to check validation of +### `classify_compilers` + +Classify compilers as legacy or non-legacy + +**Supports noop?** false + +#### Parameters + +##### `compiler_hosts` + +Data type: `Array[String]` + +List of FQDNs of compilers + ### `code_manager` Perform various code manager actions From 714f206994f9bb11d4ce21bee2e3b269d18d309e Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Tue, 30 Jul 2024 10:44:37 +0100 Subject: [PATCH 3/6] PE-38768 Linting fixes --- manifests/setup/legacy_compiler_group.pp | 9 +++---- tasks/classify_compilers.rb | 30 ++++++++++-------------- 2 files changed, 18 insertions(+), 21 deletions(-) mode change 100644 => 100755 tasks/classify_compilers.rb diff --git a/manifests/setup/legacy_compiler_group.pp b/manifests/setup/legacy_compiler_group.pp index 5745eea9..c425eae5 100644 --- a/manifests/setup/legacy_compiler_group.pp +++ b/manifests/setup/legacy_compiler_group.pp @@ -1,6 +1,7 @@ # @api private class peadm::setup::legacy_compiler_group ( - String[1] $primary_host + String[1] $primary_host, + String $internal_compiler_b_pool_address ) { Node_group { purge_behavior => none, @@ -32,7 +33,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, # Fixed namespacing 'puppetdb_port' => [8081], }, }, @@ -54,7 +55,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, # Fixed namespacing 'puppetdb_port' => [8081], }, }, @@ -69,4 +70,4 @@ node_group { 'PE Compiler': rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']], } -} +} \ No newline at end of file diff --git a/tasks/classify_compilers.rb b/tasks/classify_compilers.rb old mode 100644 new mode 100755 index e2fc9bd0..754f6ad9 --- a/tasks/classify_compilers.rb +++ b/tasks/classify_compilers.rb @@ -18,24 +18,20 @@ def classify_compiler(services) non_legacy_compilers = [] compiler_hosts.each do |compiler| - begin - cmd = "puppet infra status --host #{compiler} --format=json" - stdout, stderr, status = Open3.capture3(cmd) - - if status.success? - services = JSON.parse(stdout) - classification = classify_compiler(services) - - if classification == :legacy - legacy_compilers << compiler - else - non_legacy_compilers << compiler - end + cmd = "puppet infra status --host #{compiler} --format=json" + stdout, stderr, status = Open3.capture3(cmd) + + if status.success? + services = JSON.parse(stdout) + classification = classify_compiler(services) + + if classification == :legacy + legacy_compilers << compiler else - STDERR.puts "Error running command for #{compiler}: #{stderr}" + non_legacy_compilers << compiler end - rescue => e - STDERR.puts "Error processing #{compiler}: #{e.message}" + else + STDERR.puts "Error running command for #{compiler}: #{stderr}" end end @@ -44,4 +40,4 @@ def classify_compiler(services) 'compilers' => non_legacy_compilers } -puts result.to_json \ No newline at end of file +puts result.to_json From 9007bc6e3b1c02065314ce8c76d6b648e90c9be7 Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Tue, 30 Jul 2024 11:05:41 +0100 Subject: [PATCH 4/6] PE-38768 Linting fixes --- manifests/setup/legacy_compiler_group.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/setup/legacy_compiler_group.pp b/manifests/setup/legacy_compiler_group.pp index c425eae5..58afc277 100644 --- a/manifests/setup/legacy_compiler_group.pp +++ b/manifests/setup/legacy_compiler_group.pp @@ -33,7 +33,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, # Fixed namespacing + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, @@ -55,7 +55,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, # Fixed namespacing + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, From 482380cd0d69a5481aacb3646ca5064b327b28ae Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Tue, 30 Jul 2024 11:17:29 +0100 Subject: [PATCH 5/6] PE-38768 Linting fixes --- manifests/setup/legacy_compiler_group.pp | 2 +- manifests/setup/node_manager.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/setup/legacy_compiler_group.pp b/manifests/setup/legacy_compiler_group.pp index 58afc277..ea8e8e69 100644 --- a/manifests/setup/legacy_compiler_group.pp +++ b/manifests/setup/legacy_compiler_group.pp @@ -55,7 +55,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_a_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, diff --git a/manifests/setup/node_manager.pp b/manifests/setup/node_manager.pp index 47acd960..b6d5f096 100644 --- a/manifests/setup/node_manager.pp +++ b/manifests/setup/node_manager.pp @@ -253,7 +253,7 @@ ], classes => { 'puppet_enterprise::profile::master' => { - 'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ }, + 'puppetdb_host' => [$internal_compiler_a_pool_address].filter |$_| { $_ }, 'puppetdb_port' => [8081], }, }, From 3ca08973d1cbd858d58e3d3881c129bc49fec862 Mon Sep 17 00:00:00 2001 From: Aaron Shannon Date: Tue, 30 Jul 2024 14:25:17 +0100 Subject: [PATCH 6/6] PE-38768 Linting fixes --- manifests/setup/legacy_compiler_group.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/setup/legacy_compiler_group.pp b/manifests/setup/legacy_compiler_group.pp index ea8e8e69..24041e4a 100644 --- a/manifests/setup/legacy_compiler_group.pp +++ b/manifests/setup/legacy_compiler_group.pp @@ -1,7 +1,6 @@ # @api private class peadm::setup::legacy_compiler_group ( - String[1] $primary_host, - String $internal_compiler_b_pool_address + String[1] $primary_host ) { Node_group { purge_behavior => none,