Skip to content

Commit 5ce7241

Browse files
authored
Merge pull request #369 from jmtd/OPENJDK-2009-JAVA_OPTS
[OPENJDK-2009] let JAVA_OPTS override all tuning parameters (ubi8)
2 parents 695b411 + ec0aebd commit 5ce7241

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

modules/jvm/api/module.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
schema_version: 1
2+
23
name: jboss.container.java.jvm.api
34
version: '1.0'
45
description: ^
@@ -7,12 +8,15 @@ description: ^
78
variables listed within this module to configure the JVM appropriately.
89

910
envs:
10-
- name: JAVA_OPTS
11-
description: JVM options passed to the `java` command.
12-
example: "-verbose:class"
13-
- name: JAVA_OPTS_APPEND
14-
description: User specified Java options to be appended to generated options in JAVA_OPTS.
15-
example: "-Dsome.property=foo"
11+
- name: JAVA_OPTS
12+
description: If set, this prevents all default and generated options (such
13+
as JVM and GC tuning, proxy settings, etc.) from being applied. Instead the
14+
user should specify exactly the `java` options they want in this variable.
15+
example: "-verbose:class"
16+
- name: JAVA_OPTS_APPEND
17+
description: User specified Java options to be appended to the generated options.
18+
This variable has no effect if `JAVA_OPTS` has been defined.
19+
example: "-Dsome.property=foo"
1620
- name: JAVA_MAX_MEM_RATIO
1721
description:
1822
Specify the maximum heap memory. Corresponds to the JVM argument
@@ -69,8 +73,3 @@ envs:
6973
- name: GC_CONTAINER_OPTIONS
7074
description: specify Java GC to use. The value of this variable should contain the necessary JRE command-line options to specify the required GC, which will override the default of `-XX:+UseParallelGC`.
7175
example: -XX:+UseG1GC
72-
# deprecated
73-
- name: JAVA_OPTIONS
74-
description: JVM options passed to the `java` command. Use **JAVA_OPTS**.
75-
example: "-verbose:class"
76-

modules/run/artifacts/opt/jboss/container/java/run/run-java.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ run_java_options() {
139139

140140
# Combine all java options
141141
get_java_options() {
142-
local java_opts
142+
local jvm_opts
143143
local debug_opts
144+
local proxy_opts
145+
local opts
144146
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options" ]; then
145-
java_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
147+
jvm_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/java-default-options)
146148
fi
147149
if [ -f "${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options" ]; then
148150
debug_opts=$(${JBOSS_CONTAINER_JAVA_JVM_MODULE}/debug-options)
@@ -151,8 +153,11 @@ get_java_options() {
151153
source "${JBOSS_CONTAINER_JAVA_PROXY_MODULE}/proxy-options"
152154
proxy_opts="$(proxy_options)"
153155
fi
154-
# Normalize spaces with awk (i.e. trim and elimate double spaces)
155-
echo "${JAVA_OPTS} $(run_java_options) ${debug_opts} ${proxy_opts} ${java_opts} ${JAVA_OPTS_APPEND}" | awk '$1=$1'
156+
157+
# S2I_RUN_OPTS may have been set externally, e.g. in s2i/run
158+
opts=${JAVA_OPTS-$(run_java_options) ${S2I_RUN_OPTS} ${debug_opts} ${proxy_opts} ${jvm_opts} ${JAVA_OPTS_APPEND}}
159+
# Normalize spaces with awk (i.e. trim and eliminate double spaces)
160+
echo "${opts}" | awk '$1=$1'
156161
}
157162

158163
# Read in a classpath either from a file with a single line, colon separated

modules/s2i/bash/artifacts/usr/local/s2i/run

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ if test -r "${JBOSS_CONTAINER_MAVEN_DEFAULT_MODULE}/scl-enable-maven"; then
1717
source "${JBOSS_CONTAINER_MAVEN_DEFAULT_MODULE}/scl-enable-maven"
1818
fi
1919

20-
JAVA_OPTS="${JAVA_OPTS:-${JAVA_OPTIONS}}"
20+
if [ -z "${JAVA_OPTS+isunset}" ] && [ -n "${JAVA_OPTIONS+isset}" ]; then
21+
JAVA_OPTS="$JAVA_OPTIONS"
22+
fi
23+
2124
if [ -f "${JBOSS_CONTAINER_JOLOKIA_MODULE}/jolokia-opts" ]; then
2225
# Always include jolokia-opts, which can be empty if switched off via env
23-
JAVA_OPTS="${JAVA_OPTS} $(${JBOSS_CONTAINER_JOLOKIA_MODULE}/jolokia-opts)"
26+
S2I_RUN_OPTS="${S2I_RUN_OPTS} $(${JBOSS_CONTAINER_JOLOKIA_MODULE}/jolokia-opts)"
2427
fi
2528
if [ -f "${JBOSS_CONTAINER_PROMETHEUS_MODULE}/prometheus-opts" ]; then
26-
JAVA_OPTS="${JAVA_OPTS} $(source ${JBOSS_CONTAINER_PROMETHEUS_MODULE}/prometheus-opts && get_prometheus_opts)"
29+
S2I_RUN_OPTS="${S2I_RUN_OPTS} $(source ${JBOSS_CONTAINER_PROMETHEUS_MODULE}/prometheus-opts && get_prometheus_opts)"
2730
fi
31+
32+
export S2I_RUN_OPTS
2833
export JAVA_OPTS
2934
export JAVA_OPTIONS="$JAVA_OPTS"
3035

modules/s2i/bash/module.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ description: Customization of common Maven S2I for Java S2I image.
66
envs:
77
- name: JBOSS_CONTAINER_JAVA_S2I_MODULE
88
value: /opt/jboss/container/java/s2i
9+
# deprecated
10+
- name: JAVA_OPTIONS
11+
description:
12+
If defined and `JAVA_OPTS` is not defined, use this value to
13+
populate `JAVA_OPTS`, overriding any JVM tuning parameters
14+
generated by the container run scripts.
15+
Deprecated. Please use `JAVA_OPTS` instead.
16+
example: "-verbose:class"
917

1018
execute:
1119
- script: configure.sh

tests/features/java/runtime.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,28 @@ Feature: Openshift OpenJDK Runtime tests
4242
| variable | value |
4343
| JAVA_APP_NAME | foo bar |
4444
Then container log should not contain exec: bar': not found
45+
46+
@ubi8
47+
Scenario: Check JAVA_OPTS overrides defaults (OPENJDK-2009)
48+
Given container is started with env
49+
| variable | value |
50+
| JAVA_OPTS | --show-version |
51+
Then container log should not contain -XX:MaxRAMPercentage
52+
53+
@ubi8
54+
Scenario: Check empty JAVA_OPTS overrides defaults (OPENJDK-2009)
55+
Given container is started with env
56+
| variable | value |
57+
| JAVA_OPTS | |
58+
Then container log should not contain -XX:MaxRAMPercentage
59+
60+
# builder images only
61+
@ubi8/openjdk-8
62+
@ubi8/openjdk-11
63+
@ubi8/openjdk-17
64+
Scenario: JAVA_OPTIONS sets JAVA_OPTS and overrides defaults (OPENJDK-2009)
65+
Given container is started with env
66+
| variable | value |
67+
| JAVA_OPTIONS | --show-version |
68+
Then container log should not contain -XX:MaxRAMPercentage
69+
And container log should contain --show-version

0 commit comments

Comments
 (0)