apiVersion: v1 data: setup-hidden.sh: |- #!/bin/bash . /opt/bitnami/scripts/mongodb-env.sh echo "Advertised Hostname: $MONGODB_ADVERTISED_HOSTNAME" echo "Advertised Port: $MONGODB_ADVERTISED_PORT_NUMBER" echo "Configuring node as a hidden node" export MONGODB_REPLICA_SET_MODE="hidden" export MONGODB_INITIAL_PRIMARY_ROOT_USER="$MONGODB_ROOT_USER" export MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD="$MONGODB_ROOT_PASSWORD" export MONGODB_INITIAL_PRIMARY_PORT_NUMBER="$MONGODB_PORT_NUMBER" export MONGODB_ROOT_PASSWORD="" export MONGODB_EXTRA_USERNAMES="" export MONGODB_EXTRA_DATABASES="" export MONGODB_EXTRA_PASSWORDS="" export MONGODB_ROOT_PASSWORD_FILE="" export MONGODB_EXTRA_USERNAMES_FILE="" export MONGODB_EXTRA_DATABASES_FILE="" export MONGODB_EXTRA_PASSWORDS_FILE="" exec /opt/bitnami/scripts/mongodb/entrypoint.sh /opt/bitnami/scripts/mongodb/run.sh setup.sh: |- #!/bin/bash . /opt/bitnami/scripts/mongodb-env.sh . /opt/bitnami/scripts/libfs.sh . /opt/bitnami/scripts/liblog.sh . /opt/bitnami/scripts/libvalidations.sh if is_empty_value "$MONGODB_ADVERTISED_PORT_NUMBER"; then export MONGODB_ADVERTISED_PORT_NUMBER="$MONGODB_PORT_NUMBER" fi info "Advertised Hostname: $MONGODB_ADVERTISED_HOSTNAME" info "Advertised Port: $MONGODB_ADVERTISED_PORT_NUMBER" # Check for existing replica set in case there is no data in the PVC # This is for cases where the PVC is lost or for MongoDB caches without # persistence current_primary="" if is_dir_empty "${MONGODB_DATA_DIR}/db"; then info "Data dir empty, checking if the replica set already exists" current_primary=$(mongosh admin --host "appsmith-mongodb-0.appsmith-mongodb-headless.appsmith.svc.cluster.local:27017,appsmith-mongodb-1.appsmith-mongodb-headless.appsmith.svc.cluster.local:27017" --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD --eval 'db.runCommand("ismaster")' | awk -F\' '/primary/ {print $2}') if ! is_empty_value "$current_primary"; then info "Detected existing primary: ${current_primary}" fi fi if ! is_empty_value "$current_primary" && [[ "$MONGODB_ADVERTISED_HOSTNAME:$MONGODB_ADVERTISED_PORT_NUMBER" == "$current_primary" ]]; then info "Advertised name matches current primary, configuring node as a primary" export MONGODB_REPLICA_SET_MODE="primary" elif ! is_empty_value "$current_primary" && [[ "$MONGODB_ADVERTISED_HOSTNAME:$MONGODB_ADVERTISED_PORT_NUMBER" != "$current_primary" ]]; then info "Current primary is different from this node. Configuring the node as replica of ${current_primary}" export MONGODB_REPLICA_SET_MODE="secondary" export MONGODB_INITIAL_PRIMARY_HOST="${current_primary%:*}" export MONGODB_INITIAL_PRIMARY_PORT_NUMBER="${current_primary#*:}" export MONGODB_SET_SECONDARY_OK="yes" elif [[ "$MY_POD_NAME" = "appsmith-mongodb-0" ]]; then info "Pod name matches initial primary pod name, configuring node as a primary" export MONGODB_REPLICA_SET_MODE="primary" else info "Pod name doesn't match initial primary pod name, configuring node as a secondary" export MONGODB_REPLICA_SET_MODE="secondary" export MONGODB_INITIAL_PRIMARY_PORT_NUMBER="$MONGODB_PORT_NUMBER" fi if [[ "$MONGODB_REPLICA_SET_MODE" == "secondary" ]]; then export MONGODB_INITIAL_PRIMARY_ROOT_USER="$MONGODB_ROOT_USER" export MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD="$MONGODB_ROOT_PASSWORD" export MONGODB_ROOT_PASSWORD="" export MONGODB_EXTRA_USERNAMES="" export MONGODB_EXTRA_DATABASES="" export MONGODB_EXTRA_PASSWORDS="" export MONGODB_ROOT_PASSWORD_FILE="" export MONGODB_EXTRA_USERNAMES_FILE="" export MONGODB_EXTRA_DATABASES_FILE="" export MONGODB_EXTRA_PASSWORDS_FILE="" fi exec /opt/bitnami/scripts/mongodb/entrypoint.sh /opt/bitnami/scripts/mongodb/run.sh kind: ConfigMap metadata: labels: app.kubernetes.io/component: mongodb app.kubernetes.io/instance: release-name app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: mongodb helm.sh/chart: mongodb-12.1.16 name: appsmith-mongodb-scripts namespace: appsmith