@@ -24,9 +24,14 @@ MONGODB_APP_PASSWORD=datapass
2424MONGODB_APP_DATABASE=${ZENKO_MONGODB_DATABASE:- datadb}
2525MONGODB_RS_KEY=0123456789abcdef
2626
27- MONGODB_SHARD_COUNT=${MONGODB_SHARD_COUNT:- 1}
27+ # Constants for valid topologies for CI tests
28+ # We support multiple shards per host, or one shard per host, up to 9 nodes
29+ # The first number is the number of nodes, the second is the number of shards
30+ readonly MONGODB_VALID_TOPOLOGIES=(
31+ " 1:1" " 1:2" " 3:1" " 3:3" " 6:1" " 6:2" " 6:6" " 9:1" " 9:3" " 9:9" " 12:1" " 12:4" " 12:12"
32+ )
2833
29- source " ${DIR} /generate-kustomization.sh " && generate_kustomization " ${NODE_COUNT :- 1}" " ${MONGODB_SHARD_COUNT} "
34+ MONGODB_SHARD_COUNT= ${MONGODB_SHARD_COUNT :- 1}
3035
3136ENABLE_KEYCLOAK_HTTPS=${ENABLE_KEYCLOAK_HTTPS:- ' false' }
3237
@@ -116,6 +121,53 @@ stringData:
116121 mongodb-replica-set-key: $MONGODB_RS_KEY
117122EOF
118123
124+ # Validate that the current topology is correct
125+ get_mongodb_topology_file () {
126+ local node_count=$1
127+ local shard_count=$2
128+
129+ local base_yaml_name=" mongodb-sharded-${node_count} -node"
130+
131+ # Validate topology
132+ local topology_key=" ${node_count} :${shard_count} "
133+ if [[ ! " ${MONGODB_VALID_TOPOLOGIES[*]} " =~ " ${topology_key} " ]]; then
134+ echo " Error: Invalid topology - ${node_count} nodes, ${shard_count} shards"
135+ exit 1
136+ fi
137+
138+ # Adjust base YAML name if there are multiple shards
139+ [[ " $shard_count " -gt 1 ]] && base_yaml_name=" ${base_yaml_name} -${shard_count} -shards"
140+ base_yaml_name=" ${base_yaml_name} .yaml"
141+
142+ # ensure base file exists
143+ local base_yaml_path=" ${DIR} /_build/root/deploy/${base_yaml_name} "
144+ if [ ! -f " $base_yaml_path " ]; then
145+ echo " Error: Base YAML file not found at ${base_yaml_path} "
146+ exit 1
147+ fi
148+
149+ echo " $base_yaml_path "
150+ }
151+
152+ # MongoDB selectors are not supported in the CI.
153+ # So we remove them and let the provisioner handle the
154+ # volume provisioning.
155+ patch_mongodb_selector () {
156+ local base_yaml_path=$1
157+ local shard_count=$2
158+
159+ # Remove volume selectors from mongos StatefulSet
160+ yq eval ' select(.kind == "StatefulSet" and .metadata.name == "data-db-mongodb-sharded-mongos") |= del(.spec.volumeClaimTemplates[].spec.selector)' -i " $base_yaml_path "
161+
162+ # Remove volume selectors from configsvr StatefulSet
163+ yq eval ' select(.kind == "StatefulSet" and .metadata.name == "data-db-mongodb-sharded-configsvr") |= del(.spec.volumeClaimTemplates[].spec.selector)' -i " $base_yaml_path "
164+
165+ # Remove volume selectors from shard StatefulSets
166+ for (( i= 0 ; i< shard_count; i++ )) ; do
167+ yq eval " select(.kind == \" StatefulSet\" and .metadata.name == \" data-db-mongodb-sharded-shard${i} -data\" ) |= del(.spec.volumeClaimTemplates[].spec.selector)" -i " $base_yaml_path "
168+ done
169+ }
170+
119171build_solution_base_manifests () {
120172 echo ' build solution-base manifests'
121173 MANIFEST_ONLY=true $SOLUTION_BASE_DIR /build.sh
@@ -139,24 +191,6 @@ build_solution_base_manifests() {
139191 sed -i " s/MONGODB_SHARDSERVER_RAM_LIMIT/${MONGODB_SHARDSERVER_RAM_LIMIT} /g" $DIR /_build/root/deploy/*
140192 sed -i " s/MONGODB_SHARDSERVER_RAM_REQUEST/${MONGODB_SHARDSERVER_RAM_REQUEST} /g" $DIR /_build/root/deploy/*
141193 sed -i " s/MONGODB_MONGOS_RAM_REQUEST/${MONGODB_MONGOS_RAM_REQUEST} /g" $DIR /_build/root/deploy/*
142-
143- # Limits and requests for MongoDB are computed based on the current system
144- # Detect total system RAM in GiB
145- TOTAL_RAM_GB=$( awk ' /MemTotal/ {printf "%.0f", $2/1024/1024}' /proc/meminfo)
146-
147- # Compute MongoDB settings based on the total RAM
148- MONGODB_WIRETIGER_CACHE_SIZE_GB=$(( TOTAL_RAM_GB * 335 / 1000 ))
149- MONGODB_MONGOS_RAM_LIMIT=$(( TOTAL_RAM_GB * 165 / 1000 )) Gi
150- MONGODB_SHARDSERVER_RAM_LIMIT=$(( 2 * MONGODB_WIRETIGER_CACHE_SIZE_GB)) Gi
151- MONGODB_SHARDSERVER_RAM_REQUEST=${MONGODB_WIRETIGER_CACHE_SIZE_GB} Gi
152- MONGODB_MONGOS_RAM_REQUEST=$(( TOTAL_RAM_GB * 33 / 1000 )) Gi
153-
154- # Replace values before deploying
155- sed -i " s/MONGODB_SHARDSERVER_EXTRA_FLAGS/--wiredTigerCacheSizeGB=${MONGODB_WIRETIGER_CACHE_SIZE_GB} /g" $DIR /_build/root/deploy/*
156- sed -i " s/MONGODB_MONGOS_RAM_LIMIT/${MONGODB_MONGOS_RAM_LIMIT} /g" $DIR /_build/root/deploy/*
157- sed -i " s/MONGODB_SHARDSERVER_RAM_LIMIT/${MONGODB_SHARDSERVER_RAM_LIMIT} /g" $DIR /_build/root/deploy/*
158- sed -i " s/MONGODB_SHARDSERVER_RAM_REQUEST/${MONGODB_SHARDSERVER_RAM_REQUEST} /g" $DIR /_build/root/deploy/*
159- sed -i " s/MONGODB_MONGOS_RAM_REQUEST/${MONGODB_MONGOS_RAM_REQUEST} /g" $DIR /_build/root/deploy/*
160194}
161195
162196get_image_from_deps () {
@@ -193,13 +227,19 @@ mongodb_wait_for_shards() {
193227
194228mongodb_sharded () {
195229 local SOLUTION_REGISTRY=metalk8s-registry-from-config.invalid/zenko-base-${VERSION_FULL}
230+ local node_count=${NODE_COUNT:- 1}
231+ local shard_count=${MONGODB_SHARD_COUNT}
232+
233+ local base_yaml_path=$( get_mongodb_topology_file $node_count $shard_count )
234+
235+ sed -i " s|${SOLUTION_REGISTRY} /mongodb-sharded:.*|$( get_image_from_deps mongodb-sharded) |g" " $base_yaml_path "
236+ sed -i " s|${SOLUTION_REGISTRY} /os-shell:.*|$( get_image_from_deps mongodb-shell) |g" " $base_yaml_path "
237+ sed -i " s|${SOLUTION_REGISTRY} /mongodb-exporter:.*|$( get_image_from_deps mongodb-sharded-exporter) |g" " $base_yaml_path "
196238
197- kustomize edit set image \
198- $SOLUTION_REGISTRY /mongodb-sharded=$( get_image_from_deps mongodb-sharded) \
199- $SOLUTION_REGISTRY /os-shell=$( get_image_from_deps mongodb-shell) \
200- $SOLUTION_REGISTRY /mongodb-exporter=$( get_image_from_deps mongodb-sharded-exporter)
239+ # Ensure we use no selector as the provisioner cannot handle them
240+ patch_mongodb_selector " $base_yaml_path " " $shard_count "
201241
202- kubectl apply -k " ${DIR} "
242+ kubectl apply -f " $base_yaml_path "
203243
204244 kubectl rollout status statefulset data-db-mongodb-sharded-mongos --timeout=5m
205245 kubectl rollout status statefulset data-db-mongodb-sharded-configsvr --timeout=5m
0 commit comments