Skip to content

Commit 8c239a3

Browse files
committed
Use jvm.options.d folder on ES 7.7.0+
1 parent 1e667ce commit 8c239a3

File tree

4 files changed

+108
-11
lines changed

4 files changed

+108
-11
lines changed

manifests/config.pp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,31 @@
177177
mode => '0440',
178178
}
179179

180-
# Add any additional JVM options
181-
$elasticsearch::jvm_options.each |String $jvm_option| {
182-
file_line { "jvm_option_${jvm_option}":
183-
ensure => present,
184-
path => "${elasticsearch::configdir}/jvm.options",
185-
line => $jvm_option,
186-
notify => $elasticsearch::_notify_service,
180+
if ($elasticsearch::version != false and versioncmp($elasticsearch::version, '7.7.0') >= 0) {
181+
# https://www.elastic.co/guide/en/elasticsearch/reference/master/advanced-configuration.html#set-jvm-options
182+
# https://github.com/elastic/elasticsearch/pull/51882
183+
# >> "Do not modify the root jvm.options file. Use files in jvm.options.d/ instead."
184+
$_epp_hash = {
185+
sorted_jvm_options => sort(unique($elasticsearch::jvm_options)),
186+
}
187+
file { "${elasticsearch::configdir}/jvm.options.d/jvm.options":
188+
ensure => 'file',
189+
content => epp("${module_name}/etc/elasticsearch/jvm.options.d/jvm.options.epp", $_epp_hash),
190+
owner => $elasticsearch::elasticsearch_user,
191+
group => $elasticsearch::elasticsearch_group,
192+
mode => '0640',
193+
notify => $elasticsearch::_notify_service,
194+
}
195+
}
196+
else {
197+
# Add any additional JVM options
198+
$elasticsearch::jvm_options.each |String $jvm_option| {
199+
file_line { "jvm_option_${jvm_option}":
200+
ensure => present,
201+
path => "${elasticsearch::configdir}/jvm.options",
202+
line => $jvm_option,
203+
notify => $elasticsearch::_notify_service,
204+
}
187205
}
188206
}
189207

spec/classes/000_elasticsearch_init_spec.rb

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,16 @@
412412
}
413413
end
414414

415-
describe 'setting jvm_options' do
415+
describe 'setting jvm_options before version 7.7.0' do
416416
jvm_options = [
417417
'-Xms16g',
418418
'-Xmx16g'
419419
]
420420

421421
let(:params) do
422422
default_params.merge(
423-
jvm_options: jvm_options
423+
jvm_options: jvm_options,
424+
version: '7.0.0'
424425
)
425426
end
426427

@@ -436,6 +437,25 @@
436437
end
437438
end
438439

440+
describe 'setting jvm_options after version 7.7.0' do
441+
jvm_options = [
442+
'-Xms16g',
443+
'-Xmx16g'
444+
]
445+
446+
let(:params) do
447+
default_params.merge(
448+
jvm_options: jvm_options,
449+
version: '7.7.0'
450+
)
451+
end
452+
453+
it {
454+
expect(subject).to contain_file('/etc/elasticsearch/jvm.options.d/jvm.options').
455+
with(ensure: 'file')
456+
}
457+
end
458+
439459
context 'with restart_on_change => true' do
440460
let(:params) do
441461
default_params.merge(
@@ -450,10 +470,11 @@
450470
}
451471
end
452472

453-
describe 'setting jvm_options triggers restart' do
473+
describe 'setting jvm_options triggers restart before version 7.7.0' do
454474
let(:params) do
455475
super().merge(
456-
jvm_options: ['-Xmx16g']
476+
jvm_options: ['-Xmx16g'],
477+
version: '7.0.0'
457478
)
458479
end
459480

@@ -462,6 +483,20 @@
462483
that_notifies('Service[elasticsearch]')
463484
}
464485
end
486+
487+
describe 'setting jvm_options triggers restart after version 7.7.0' do
488+
let(:params) do
489+
super().merge(
490+
jvm_options: ['-Xmx16g'],
491+
version: '7.7.0'
492+
)
493+
end
494+
495+
it {
496+
expect(subject).to contain_file('/etc/elasticsearch/jvm.options.d/jvm.options').
497+
that_notifies('Service[elasticsearch]')
498+
}
499+
end
465500
end
466501

467502
# This check helps catch dependency cycles.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'jvm.options.epp' do
6+
let :harness do
7+
TemplateHarness.new(
8+
'templates/etc/elasticsearch/jvm.options.d/jvm.options.epp'
9+
)
10+
end
11+
12+
it 'render the same string each time' do
13+
harness.set(
14+
'@_sorted_jvm_options', [
15+
'-Xms2g',
16+
'-Xmx2g'
17+
]
18+
)
19+
20+
first_render = harness.run
21+
second_render = harness.run
22+
23+
expect(first_render).to eq(second_render)
24+
end
25+
26+
it 'test content' do
27+
harness.set(
28+
'@_sorted_jvm_options', [
29+
'-Xms2g',
30+
'-Xmx2g'
31+
]
32+
)
33+
34+
expect(harness.run).to eq(%(
35+
### MANAGED BY PUPPET ###
36+
-Xms2g
37+
-Xmx2g
38+
).config)
39+
end
40+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### MANAGED BY PUPPET ###
2+
<% $sorted_jvm_options.each |$jvm_option| { -%>
3+
<%= $jvm_option %>
4+
<% } -%>

0 commit comments

Comments
 (0)