How to inject a custom CLI script as a ConfigMap in OpenShift for EAP/RH-SSO ?
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.x
- Red Hat Single Sign On (RHSSO)
- 7.x
Issue
- How to update/modify existing DataSource Connection Pool Parameters in RHSSO running on OpenShift Using
Custom CLI Scripts ? - How to inject a custom CLI script as a ConfigMap in OpenShift for EAP/RH-SSO ?
Resolution
- To dynamically apply DataSource connection pool configurations, use a custom CLI script injected via a
ConfigMap. This approach modifies the RHSSO/ EAP server configuration during deployment.
- Prepare CLI Script (extensions.cli)
Create a script to update the DataSource configuration:
embed-server --std-out=echo --server-config=standalone-openshift.xml
batch
/subsystem=datasources/data-source=<DATASOURCE_NAME>:write-attribute(name=min-pool-size,value=5)
/subsystem=datasources/data-source=<DATASOURCE_NAME>:write-attribute(name=max-pool-size,value=20)
/subsystem=datasources/data-source=<DATASOURCE_NAME>:write-attribute(name=valid-connection-checker-class-name,value=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker)
/subsystem=datasources/data-source=<DATASOURCE_NAME>:write-attribute(name=validate-on-match,value=true)
/subsystem=datasources/data-source=<DATASOURCE_NAME>:write-attribute(name=exception-sorter-class-name,value=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter)
run-batch
quit
Replace
- Create a Post-Configuration Script (postconfigure.sh)
- This script executes the CLI commands during deployment:
#!/bin/sh
echo "Executing postconfigure.sh"
$JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/extensions/extensions.cli
- Create a ConfigMap in OpenShift
- Bundle the scripts into a ConfigMap:
oc create configmap jboss-cli --from-file=postconfigure.sh=extensions/postconfigure.sh --from-file=extensions.cli=extensions/extensions.cli
- Mount the ConfigMap into the DeploymentConfig
- Attach the ConfigMap as a volume to the SSO pod:
oc set volume DeploymentConfig/<DeploymentConfig_NAME> --add --name=jboss-cli -m /opt/eap/extensions -t configmap --configmap-name=jboss-cli --default-mode='0755'
Replace
Notes:
Execute the following steps to update the pods to use the new image that includes the updated CLI file.
To rebuild and apply updates to your application in the rhsso-76 namespace, follow these steps:
Get the Build Configuration (BC) name:
oc get bc -n rhsso-76
Start a new build using the updated CLI files:
oc start-build sso76 --from-dir=. --follow -n rhsso-76
Restart the application pods to apply the new build:
oc rollout restart dc/<your-app-name> -n rhsso-76
Replace
Ensure that the updated CLI script is correctly copied into the build context used for the image.
To verify that the changes have been successfully applied at runtime after the pod starts, execute the following:
oc rsh <pod-name>
/opt/eap/bin/jboss-cli.sh --connect
/subsystem=datasources/data-source=KeycloakDS:read-resource
This command will display the current datasource configuration, including any updated validation settings.
Alternatively, you can check the standalone-openshift.xml file to confirm whether the new datasource configuration has been added.
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.
Comments