Skip to content

Commit

Permalink
Merge pull request #105 from treydock/fix-java-opts
Browse files Browse the repository at this point in the history
Change JAVA_OPTS behavior for Keycloak
  • Loading branch information
treydock authored Dec 18, 2019
2 parents b113eec + f0286d2 commit 25444aa
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ cache: bundler
before_install:
- bundle -v
- rm -f Gemfile.lock
- gem update --system $RUBYGEMS_VERSION
- gem --version
- bundle -v
script:
Expand Down
23 changes: 23 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,27 @@

create_resources('keycloak::truststore::host', $keycloak::truststore_hosts)

if $keycloak::java_opts {
$java_opts_ensure = 'present'
} else {
$java_opts_ensure = 'absent'
}

if $keycloak::java_opts =~ Array {
$java_opts = join($keycloak::java_opts, ' ')
} else {
$java_opts = $keycloak::java_opts
}
if $keycloak::java_opts_append {
$_java_opts = "\$JAVA_OPTS ${java_opts}"
} else {
$_java_opts = $java_opts
}
file_line { 'standalone.conf-JAVA_OPTS':
ensure => $java_opts_ensure,
path => "${keycloak::install_base}/bin/standalone.conf",
line => "JAVA_OPTS=\"${_java_opts}\"",
match => '^JAVA_OPTS=',
notify => Class['keycloak::service'],
}
}
8 changes: 5 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
# @param service_bind_address
# Bind address for Keycloak service.
# Default is '0.0.0.0'.
# @param service_java_opts
# @param java_opts
# Sets additional options to Java virtual machine environment variable.
# @param java_opts_append
# Determine if $JAVA_OPTS should be appended to when setting `java_opts` parameter
# @param service_extra_opts
# Additional options added to the end of the service command-line.
# @param manage_user
Expand Down Expand Up @@ -194,8 +196,8 @@
Boolean $service_hasstatus = true,
Boolean $service_hasrestart = true,
Stdlib::IP::Address $service_bind_address = '0.0.0.0',
Optional[Variant[String, Array]]
$service_java_opts = undef,
Optional[Variant[String, Array]] $java_opts = undef,
Boolean $java_opts_append = true,
Optional[String] $service_extra_opts = undef,
Boolean $manage_user = true,
String $user = 'keycloak',
Expand Down
3 changes: 2 additions & 1 deletion spec/acceptance/1_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ class { 'keycloak':
end
end

context 'default with proxy_https' do
context 'changes to defaults' do
it 'runs successfully' do
pp = <<-EOS
include mysql::server
class { 'keycloak':
datasource_driver => 'mysql',
proxy_https => true,
java_opts => '-Xmx512m -Xms64m',
}
EOS

Expand Down
38 changes: 38 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,51 @@
)
end

it do
is_expected.to contain_file_line('standalone.conf-JAVA_OPTS').with(
ensure: 'absent',
path: '/opt/keycloak-6.0.1/bin/standalone.conf',
line: 'JAVA_OPTS="$JAVA_OPTS "',
match: '^JAVA_OPTS=',
notify: 'Class[Keycloak::Service]',
)
end

context 'when tech_preview_features defined' do
let(:params) { { tech_preview_features: ['account_api'] } }

it do
verify_exact_file_contents(catalogue, '/opt/keycloak-6.0.1/standalone/configuration/profile.properties', ['feature.account_api=enabled'])
end
end

context 'when java_opts defined' do
let(:params) { { java_opts: '-Xmx512m -Xms64m' } }

it do
is_expected.to contain_file_line('standalone.conf-JAVA_OPTS').with(
ensure: 'present',
path: '/opt/keycloak-6.0.1/bin/standalone.conf',
line: 'JAVA_OPTS="$JAVA_OPTS -Xmx512m -Xms64m"',
match: '^JAVA_OPTS=',
notify: 'Class[Keycloak::Service]',
)
end

context 'when java_opts_append is false' do
let(:params) { { java_opts: '-Xmx512m -Xms64m', java_opts_append: false } }

it do
is_expected.to contain_file_line('standalone.conf-JAVA_OPTS').with(
ensure: 'present',
path: '/opt/keycloak-6.0.1/bin/standalone.conf',
line: 'JAVA_OPTS="-Xmx512m -Xms64m"',
match: '^JAVA_OPTS=',
notify: 'Class[Keycloak::Service]',
)
end
end
end
end

context 'keycloak::service' do
Expand Down
7 changes: 0 additions & 7 deletions templates/keycloak.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ Type=idle
<% if scope['keycloak::service_environment_file'] -%>
EnvironmentFile=<%= scope['keycloak::service_environment_file'] %>
<% end -%>
<% if scope['keycloak::service_java_opts'] -%>
<% if scope['keycloak::server_java_opts'].is_a?(Array) -%>
Environment="JAVA_OPTS=$JAVA_OPTS <%= scope['keycloak::service_java_opts'].join(' ') %>"
<% else %>
Environment="JAVA_OPTS=$JAVA_OPTS <%= scope['keycloak::service_java_opts'] %>"
<% end -%>
<% end -%>
User=<%= scope['keycloak::user'] %>
Group=<%= scope['keycloak::group'] %>
<% if scope['keycloak::operating_mode'] == 'standalone'-%>
Expand Down

0 comments on commit 25444aa

Please sign in to comment.