[bitnami/cassandra] Add possibility to update cassandra.yaml from the environment variables (#63358)

This commit is contained in:
Dmitriy Pavlov
2024-03-07 03:57:24 -05:00
committed by GitHub
parent 226e7f32ff
commit 97b7ba06d9
3 changed files with 53 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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