The AMQ Pod consist of two containers:
-
Init container
This init container runs an
artemis create …command - and additional scripts - to generate an AMQ configuration based on the parameters set in CRs. This config is recreated - not persisted - every time the Pod starts, that’s how changes in the CRs are being applied. -
Broker container
The main container runs
artemis run …with the config generated by the init container (at/home/jboss/amq-broker) using thedatadirectories from the persistent volume (/opt/my-broker/data).
For the container startup scripts see launch.sh in the AMQ Broker Container Image Source Code downloads for the release being used.
Related links:
The operator supports the most common use cases, but we can’t set all the parameters for the broker, we need a custom init container for advanced configuration. The source for a custom init container is simple:
. ├── Dockerfile └── post-config.sh
-
Dockerfile: Make sure you build FROM the original init container matching your AMQ version.
FROM registry.redhat.io/amq7/amq-broker-init-rhel8:7.10-28 ADD ./post-config.sh /amq/scripts/post-config.sh
-
post-config.sh: This script is called after the
artemis createcommand. We can modify the generated configuration in$CONFIG_INSTANCE_DIRdirectory.
The built init container then must be added to the ActiveMQArtemis CR:
spec:
deploymentPlan:
initImage: image-registry.openshift-image-registry.svc:5000/myproject/my-amq-init:latest
Regular rebuild of the custom init container is recommended as new versions of the init container is released (~4-6 weeks).
The AMQ config files generated by the init container will be available at $CONFIG_INSTANCE_DIR location in the post-config.sh. We can use the basic Linux tool (sed, awk…) to edit these files or add additional files to the directory structure. Generally it’s recommended to modify small sections or append to generated config files instead for overwriting them, to avoid any issues when a new operator version may introduce changes in these files.
Edit a broker.xml line with sed for example:
sed -i 's|<critical-analyzer>.*<\/critical-analyzer>|<critical-analyzer>false</critical-analyzer>|' ${CONFIG_INSTANCE_DIR}/etc/broker.xml
Multiline edit is possible like:
sed -i ':a;N;$!ba s|<security-settings>|<security-invalidation-interval>'$SECURITY_INVALIDATION_INTERVAL'</security-invalidation-interval>\n <security-settings>|' ${CONFIG_INSTANCE_DIR}/etc/broker.xml
Appending to a file:
echo >>${CONFIG_INSTANCE_DIR}/etc/artemis.profile #new line
echo 'JAVA_ARGS="$JAVA_ARGS -XX:MaxRAMPercentage=50"' >>${CONFIG_INSTANCE_DIR}/etc/artemis.profile
ConfigMaps and Secrets can be mounted to init and broker container in the ActiveMQArtemis CR (these ConfigMaps/Secrets must exist if they are listed):
spec:
deploymentPlan:
extraMounts:
configMaps:
- broker-add-vars
- broker-add-files
secrets:
- broker-add-vars-secret
- broker-add-files-secret
The entries are available as files in the containers at a fixed mount point, for example: /amq/extra/configmaps/broker-add-files/cert-users.properties. They can be copied - or linked to utilize AMQ’s config reload feature - to the $CONFIG_INSTANCE_DIR directory to add new files or overwrite the generated ones.
ln -fvs /amq/extra/configmaps/broker-add-files/cert-users.properties $CONFIG_INSTANCE_DIR/etc/
The post-config.sh script is added to the init container image itself, which is used in different environments. At this point it’s not possible to add custom environment variables with the operator - but hopefully soon - so the script can’t set environment specific values. One workaround is to read parameters from an extraMounts mounted ConfigMap (or Secret) at the beginning of the post-config.sh like this:
for config_file in /amq/extra/configmaps/broker-env-vars/*;
do
echo "Source env variables from $config_file"
source $config_file
done
Let’s assume the broker-env-vars ConfigMap has an entry envvars like below. These variables - coming from a ConfigMap - can be used in the rest of the script now.
SECURITY_INVALIDATION_INTERVAL=60000 LOG_ROTATION_SIZE=100000000 LOG_ROTATION_COUNT=3
If the ConfigMap entries are also added to artemis.profile (echo "source $config_file" >>${CONFIG_INSTANCE_DIR}/etc/artemis.profile), we can directly set or modify environment variables for the Artemis process running in the broker container, configurable per environment:
JAVA_ARGS="$JAVA_ARGS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${ARTEMIS_OOME_DUMP}"
DEBUG_ARGS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
See post-config.sh for additional details and examples.