Setting Env variables in JWS and JBoss EAP Operator in Openshift 4

Solution Verified - Updated

Environment

  • Red Hat Openshift Container Platform
    • 4.x

Issue

  • Setting Env variables in JWS Operator in Openshift 4
  • Setting Env variables in JBoss EAP Operator in Openshift 4
  • Setting Env variables in Data Grid Operator in Openshift 4

Resolution

In JWS and EAP Operator the user sets the env variables not directly via statefulset but via the custom resource (CR) spec.env.
And that's a general rule the user should not touch the intermediary deployment resources such as statefulsets, because that will be overwritten by the operator via the custom resource.
That would be the case for EAP 8 helm chart deployment for example, where the user interfaces via sts (statefulset resource).

The solution How to modify JVM options (JAVA_OPTS) for JBoss EAP in Openshift and the solution How to change JVM memory options using Openshift images with Java? tackle this problem but not for Operator deployment. And the solution Using JAVA_MAX_MEM_RATIO on container JBoss EAP 7 image handles specifically JAVA_INITIAL_MEM_RATIO and JAVA_MAX_MEM_RATIO environment variables.

Respective Custom resource

For Middleware Operators the spec.containers section must be applied on the respective custom resource:

OperatorCustom Resource
EAP OperatorWildFlyServer CR
JWS OperatorWebServer CR
SSO OperatorKeycloack CR
Data Grid OperatorInfinispan CR

Example

Example for env setting:
$ oc get wildflyserver
NAME          REPLICAS   AGE
example-env   1          84m
...
...
$ oc get wildflyserver -o yaml
apiVersion: v1
items:
- apiVersion: wildfly.org/v1alpha1
  kind: WildFlyServer
  metadata:
    name: example-env
spec:
  applicationImage: registry.redhat.io/...
  env:
    - name: JAVA_OPTS_APPEND
      value: '"-XX:MinHeapFreeRatio=11"'
...
$ oc get sts example -o yaml
apiVersion: apps/v1
kind: StatefulSet
...
  ownerReferences:
  - apiVersion: wildfly.org/v1alpha1
    kind: WildFlyServer
    name: example-env

Diagnostic Steps

The following can be used for diagnose:
a- the inspect bundle (oc adm inspect ns/NAMESPACE)
b- the WildflyServer custom resource

Components
Category
Tags

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.