From 97b7ba06d93444cf1d57e351fb7bea1f326c6546 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Thu, 7 Mar 2024 03:57:24 -0500 Subject: [PATCH] [bitnami/cassandra] Add possibility to update cassandra.yaml from the environment variables (#63358) --- .../opt/bitnami/scripts/libcassandra.sh | 25 +++++++++++++++++++ .../opt/bitnami/scripts/libcassandra.sh | 25 +++++++++++++++++++ bitnami/cassandra/README.md | 3 +++ 3 files changed, 53 insertions(+) diff --git a/bitnami/cassandra/4.0/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh b/bitnami/cassandra/4.0/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh index 9185044e3f49..591acaa8e077 100644 --- a/bitnami/cassandra/4.0/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh +++ b/bitnami/cassandra/4.0/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh @@ -1156,6 +1156,24 @@ cassandra_commitlog_conf_set() { cassandra_common_conf_set "${CASSANDRA_CONF_DIR}/commitlog_archiving.properties" "$@" } +######################## +# Set a configuration setting value to cassandra.yaml +# Globals: +# CASSANDRA_CONF_DIR +# Arguments: +# $1 - key +# $2 - value +# Returns: +# None +######################### +cassandra_yaml_conf_set() { + if ! cassandra_is_file_external "cassandra.yaml"; then + cassandra_yaml_set $1 $2 'no' + else + debug "cassandra.yaml mounted. Skipping data directory configuration" + fi +} + ######################## # Configure Cassandra configuration files from environment variables # Globals: @@ -1166,6 +1184,13 @@ cassandra_commitlog_conf_set() { # None ######################### cassandra_setup_from_environment_variables() { + # Map environment variables to config properties for cassandra.yaml + for var in "${!CASSANDRA_CFG_YAML_@}"; do + # shellcheck disable=SC2001 + key="$(echo "$var" | sed -e 's/^CASSANDRA_CFG_YAML_//g' | tr '[:upper:]' '[:lower:]')" + value="${!var}" + cassandra_yaml_conf_set "$key" "$value" + done # Map environment variables to config properties for cassandra-env.sh for var in "${!CASSANDRA_CFG_ENV_@}"; do # shellcheck disable=SC2001 diff --git a/bitnami/cassandra/4.1/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh b/bitnami/cassandra/4.1/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh index 9185044e3f49..591acaa8e077 100644 --- a/bitnami/cassandra/4.1/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh +++ b/bitnami/cassandra/4.1/debian-12/rootfs/opt/bitnami/scripts/libcassandra.sh @@ -1156,6 +1156,24 @@ cassandra_commitlog_conf_set() { cassandra_common_conf_set "${CASSANDRA_CONF_DIR}/commitlog_archiving.properties" "$@" } +######################## +# Set a configuration setting value to cassandra.yaml +# Globals: +# CASSANDRA_CONF_DIR +# Arguments: +# $1 - key +# $2 - value +# Returns: +# None +######################### +cassandra_yaml_conf_set() { + if ! cassandra_is_file_external "cassandra.yaml"; then + cassandra_yaml_set $1 $2 'no' + else + debug "cassandra.yaml mounted. Skipping data directory configuration" + fi +} + ######################## # Configure Cassandra configuration files from environment variables # Globals: @@ -1166,6 +1184,13 @@ cassandra_commitlog_conf_set() { # None ######################### cassandra_setup_from_environment_variables() { + # Map environment variables to config properties for cassandra.yaml + for var in "${!CASSANDRA_CFG_YAML_@}"; do + # shellcheck disable=SC2001 + key="$(echo "$var" | sed -e 's/^CASSANDRA_CFG_YAML_//g' | tr '[:upper:]' '[:lower:]')" + value="${!var}" + cassandra_yaml_conf_set "$key" "$value" + done # Map environment variables to config properties for cassandra-env.sh for var in "${!CASSANDRA_CFG_ENV_@}"; do # shellcheck disable=SC2001 diff --git a/bitnami/cassandra/README.md b/bitnami/cassandra/README.md index 162de8851dd0..c8f36caaffba 100644 --- a/bitnami/cassandra/README.md +++ b/bitnami/cassandra/README.md @@ -239,8 +239,11 @@ Additionally, any environment variable beginning with the following prefix will * `CASSANDRA_CFG_ENV_`: Will add the corresponding key and the provided value to `cassandra-env.sh`. * `CASSANDRA_CFG_RACKDC_`: Will add the corresponding key and the provided value to `cassandra-rackdc.properties`. * `CASSANDRA_CFG_COMMITLOG_`: Will add the corresponding key and the provided value to `commitlog_archiving.properties`. +* `CASSANDRA_CFG_YAML_`: Will add the corresponding key and the provided value to `cassandra.yaml`. For example, use `CASSANDRA_CFG_RACKDC_PREFER_LOCAL=true` in order to configure `prefer_local` in `cassandra-rackdc.properties`. +To update the `cassandra.yaml` file and set `internode_compression` to `all` use `CASSANDRA_CFG_YAML_INTERNODE_COMPRESSION=all`. +In the same way you can update nested options in the `cassandra.yaml`. For example, `CASSANDRA_CFG_YAML_CACHED_ROWS_WARN_THRESHOLD` will set `cached_rows_warn_threshold` in the `replica_filtering_protection` section. **NOTE:** Environment variables will be omitted when mounting a configuration file