Skip to content

PE-38768 classify compilers task added #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1056,6 +1057,20 @@ Data type: `String`

The certifcate name to check validation of

### <a name="classify_compilers"></a>`classify_compilers`

Classify compilers as legacy or non-legacy

**Supports noop?** false

#### Parameters

##### `compiler_hosts`

Data type: `Array[String]`

List of FQDNs of compilers

### <a name="code_manager"></a>`code_manager`

Perform various code manager actions
Expand Down
6 changes: 3 additions & 3 deletions manifests/setup/legacy_compiler_group.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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 |$_| { $_ },
'puppetdb_port' => [8081],
},
},
Expand All @@ -54,7 +54,7 @@
],
classes => {
'puppet_enterprise::profile::master' => {
'puppetdb_host' => [$internal_compiler_b_pool_address].filter |$_| { $_ },
'puppetdb_host' => [$peadm::setup::legacy_compiler_group::internal_compiler_a_pool_address].filter |$_| { $_ },
'puppetdb_port' => [8081],
},
},
Expand All @@ -69,4 +69,4 @@
node_group { 'PE Compiler':
rule => ['and', ['=', ['trusted', 'extensions', peadm::oid('peadm_legacy_compiler')], 'false']],
}
}
}
2 changes: 1 addition & 1 deletion manifests/setup/node_manager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
},
Expand Down
15 changes: 15 additions & 0 deletions tasks/classify_compilers.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}
43 changes: 43 additions & 0 deletions tasks/classify_compilers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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|
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
end

result = {
'legacy_compilers' => legacy_compilers,
'compilers' => non_legacy_compilers
}

puts result.to_json
Loading