UBI 8 OpenJDK 17 JAVA_OPTS overwrites JAVA_OPTS_APPEND
Environment
- Red hat OpenShift Container Platform (OCP)
- 4.x
- OpenJDK 17
- Image ubi8/openjdk-17:1.15-1
Issue
- UBI OpenJDK ubi8/openjdk-17:1.15-1 image
JAVA_OPTSoverwriteJAVA_OPTS_APPEND - UBI OpenJDK ubi8/openjdk-17:1.15-1 image image ignores
JAVA_OPTS_APPEND
oc new-app --context-dir=getting-started --name=quickstart --image-stream=test/openjdk-17:1.17-2~https://github.com/quarkusio/quarkus-quickstarts.git#3.2 --build-env='JAVA_OPTS=-Xmx1024M' --build-env='JAVA_OPTS_APPEND=-Dbox=fox'
- UBI OpenJDK ubi8/openjdk-17:1.15-1 breaks backward with previous versions on
JAVA_OPTSenvironment variable, which differs from ubi8/openjdk-17 behavior
Resolution
Starting on ubi8/openjdk-17:1.15-1 the JAVA_OPTS overwrites other JVM flags- and that is expected. So for most use cases: use JAVA_OPTS_APPEND it should have the same intended behavior.
Changes that were introduced in ubi8/openjdk-17:1.15-1:
- Before the image
ubi8/openjdk-17:1.15-1the behavior was: user could useJAVA_OPTSin combination toJAVA_OPTS_APPEND- behavior: combine them both. - After
ubi8/openjdk-17:1.15-1, the behavior is: usage ofJAVA_OPTSreplaces other JVM flags - behavior: java_opts replaces java_opts_append.
Finally, in case of deployment of builds, be sure the images are the same on different pods, via ImageID/shaID verification on the pod yaml.
Quarkus had a similar issue, where JAVA_OPTS_APPEND was not being used, which is now fixed in Quarkus 3.5.0.CR1+, Content from github.com is not included.Quarkus PR 35983.
Root Cause
The changes introduced on ubi8/openjdk-17:1.15-1 restore JAVA_OPTS to its original behavior, which was broken inadvertently on previous images (ubi8 images). And this aligns the behavior with the ubi9 images.
The intent behind the two variables is:
- customer-provided JAVA_OPTS overrides all our options generation
- customer-provided JAVA_OPTS_APPEND adds to our options generation.
The main recommendation is to switch to JAVA_OPTS_APPEND for appending, i.e. the user should be using JAVA_OPTS_APPEND for most use cases except advanced replacement.
| Image | Behavior |
|---|---|
| ubi8/openjdk-17:1.15-1 (before) | JAVA_OPTS: adds, and JAVA_OPTS_APPEND: adds |
| ubi8/openjdk-17:1.15-1 (after) | JAVA_OPTS: overrides, and JAVA_OPTS_APPEND: adds |
| ubi9/images | JAVA_OPTS: overrides, and JAVA_OPTS_APPEND: adds |
Diagnostic Steps
- Verify if the image is
ubi8/openjdk-17:1.15-1 - Verify on the deployment/deploymentconfig has
JAVA_OPTS. - For most use cases just use
JAVA_OPTS_APPEND - $ sed -i 's/\bJAVA_OPTS\b/JAVA_OPTS_APPEND/g' deployment.yaml can be used to automatic replacement
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.