Skip to content

Commit 3469134

Browse files
authored
Merge pull request #470 from DataDog/remicalixte/backup-keyserver
Add a backup keyserver in case the main one is down
2 parents e61af0d + be4ec4e commit 3469134

7 files changed

Lines changed: 49 additions & 6 deletions

File tree

manifests/init.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@
284284
Hash[String[1], Data] $agent6_extra_options = {},
285285
$agent5_repo_uri = $datadog_agent::params::agent5_default_repo,
286286
$agent6_repo_uri = $datadog_agent::params::agent6_default_repo,
287+
Optional[Boolean] $use_apt_backup_keyserver = $datadog_agent::params::use_apt_backup_keyserver,
288+
$apt_backup_keyserver = $datadog_agent::params::apt_backup_keyserver,
289+
$apt_keyserver = $datadog_agent::params::apt_keyserver,
287290
$apt_release = $datadog_agent::params::apt_default_release,
288291
Optional[String] $service_provider = undef,
289292
Optional[String] $agent_version = $datadog_agent::params::agent_version,
@@ -395,6 +398,12 @@
395398
default: { $_loglevel = 'INFO' }
396399
}
397400

401+
if $use_apt_backup_keyserver {
402+
$_apt_keyserver = $apt_backup_keyserver
403+
} else {
404+
$_apt_keyserver = $apt_keyserver
405+
}
406+
398407
case $::operatingsystem {
399408
'Ubuntu','Debian' : {
400409
if $agent5_enable {
@@ -406,6 +415,7 @@
406415
location => $agent5_repo_uri,
407416
release => $apt_release,
408417
skip_apt_key_trusting => $skip_apt_key_trusting,
418+
apt_keyserver => $_apt_keyserver,
409419
}
410420
} else {
411421
class { 'datadog_agent::ubuntu::agent6':
@@ -416,6 +426,7 @@
416426
location => $agent6_repo_uri,
417427
release => $apt_release,
418428
skip_apt_key_trusting => $skip_apt_key_trusting,
429+
apt_keyserver => $_apt_keyserver,
419430
}
420431
}
421432
}

manifests/params.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
$process_default_custom_words = []
3434
$logs_enabled = false
3535
$container_collect_all = false
36+
$use_apt_backup_keyserver = false
37+
$apt_backup_keyserver = 'hkp://pool.sks-keyservers.net:80'
38+
$apt_keyserver = 'hkp://keyserver.ubuntu.com:80'
3639

3740
case $::operatingsystem {
3841
'Ubuntu','Debian' : {

manifests/ubuntu/agent5.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
String $service_ensure = 'running',
2323
Boolean $service_enable = true,
2424
Optional[String] $service_provider = undef,
25+
Optional[String] $apt_keyserver = undef,
2526
) inherits datadog_agent::params{
2627

2728
ensure_packages(['apt-transport-https'])
2829

2930
if !$skip_apt_key_trusting {
3031
::datadog_agent::ubuntu::install_key { [$apt_key]:
31-
before => Apt::Source['datadog'],
32+
server => $apt_keyserver,
33+
before => Apt::Source['datadog'],
3234
}
3335
}
3436

manifests/ubuntu/agent6.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
String $service_ensure = 'running',
1414
Boolean $service_enable = true,
1515
Optional[String] $service_provider = undef,
16+
Optional[String] $apt_keyserver = undef,
1617
) inherits datadog_agent::params {
1718

1819
ensure_packages(['apt-transport-https'])
1920
if !$skip_apt_key_trusting {
2021
::datadog_agent::ubuntu::install_key { [$apt_key]:
21-
before => Apt::Source['datadog6'],
22+
server => $apt_keyserver,
23+
before => Apt::Source['datadog6'],
2224
}
2325
}
2426

manifests/ubuntu/install_key.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#
1313
#
1414
#
15-
define datadog_agent::ubuntu::install_key() {
15+
define datadog_agent::ubuntu::install_key($server) {
1616
apt::key { $name:
1717
id => $name,
18-
server => 'hkp://keyserver.ubuntu.com:80',
18+
server => $server,
1919
}
2020
}

spec/classes/datadog_agent_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,20 @@
833833
end
834834

835835
if DEBIAN_OS.include?(operatingsystem)
836-
it { should contain_class('datadog_agent::ubuntu::agent5') }
836+
it do
837+
should contain_class('datadog_agent::ubuntu::agent5')\
838+
.with_apt_keyserver('hkp://keyserver.ubuntu.com:80')
839+
end
840+
context 'use backup keyserver' do
841+
let(:params) {{
842+
:use_apt_backup_keyserver => true,
843+
:agent5_enable => true,
844+
}}
845+
it do
846+
should contain_class('datadog_agent::ubuntu::agent5')\
847+
.with_apt_keyserver('hkp://pool.sks-keyservers.net:80')
848+
end
849+
end
837850
elsif REDHAT_OS.include?(operatingsystem)
838851
it { should contain_class('datadog_agent::redhat::agent5') }
839852
end

spec/classes/datadog_agent_ubuntu_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@
1717

1818
# it should install the mirror
1919
it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') }
20-
it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') }
20+
it do
21+
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
22+
end
23+
context 'overriding keyserver' do
24+
let(:params) {{
25+
apt_keyserver: 'hkp://pool.sks-keyservers.net:80',
26+
}}
27+
it do
28+
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
29+
.with_server('hkp://pool.sks-keyservers.net:80')
30+
end
31+
end
32+
2133
it do
2234
should contain_file('/etc/apt/sources.list.d/datadog.list')\
2335
.that_notifies('exec[apt_update]')

0 commit comments

Comments
 (0)