Skip to content

Commit

Permalink
Support multiple shards in CI
Browse files Browse the repository at this point in the history
Issue: ZENKO-4641
  • Loading branch information
williamlardier committed Dec 27, 2024
1 parent e534b5b commit 7778198
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/end2end/configs/zenko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: ${ZENKO_NAME}
${ZENKO_ANNOTATIONS}
zenko.io/x-backbeat-oneshard-replicaset: data-db-mongodb-sharded-shard-0
zenko.io/x-backbeat-oneshard-replicaset-hosts: data-db-mongodb-sharded-shard0-data-0.data-db-mongodb-sharded-headless.default.svc.cluster.local:27017
zenko.io/x-backbeat-oneshard-replicaset-hosts: ${ZENKO_BACKBEAT_SHARD_HOSTS}
spec:
version: ${ZENKO_VERSION_NAME}
replicas: 1
Expand Down
10 changes: 10 additions & 0 deletions .github/scripts/end2end/deploy-zenko.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ create_encryption_secret()
export AZURE_SECRET_KEY_ENCRYPTED
}

generate_shard_hosts() {
local hosts=""
for ((i=0; i<MONGODB_SHARD_COUNT; i++)); do
if [ $i -gt 0 ]; then hosts+=","; fi
hosts+="data-db-mongodb-sharded-shard${i}-data-0.data-db-mongodb-sharded-headless.default.svc.cluster.local:27017"
done
export ZENKO_BACKBEAT_SHARD_HOSTS="$hosts"
}

create_encryption_secret
generate_shard_hosts

env $(dependencies_env) envsubst < ${ZENKOVERSION_PATH} | kubectl -n ${NAMESPACE} apply -f -
env $(dependencies_env) envsubst < ${ZENKO_CR_PATH} | kubectl -n ${NAMESPACE} apply -f -
Expand Down
99 changes: 99 additions & 0 deletions .github/scripts/end2end/generate-kustomization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

set -euo pipefail

# Constants for valid topologies for CI tests
readonly VALID_TOPOLOGIES=(
"1:1" # 1 node, 1 shard
"1:2" # 1 node, 2 shards
"3:1" # 3 nodes, 1 shard
"3:3" # 3 nodes, 3 shards
"6:1" # 6 nodes, 1 shard
"6:2" # 6 nodes, 2 shards
"6:3" # 6 nodes, 3 shards
"6:6" # 6 nodes, 6 shards
"9:1" # 9 nodes, 1 shard
"9:3" # 9 nodes, 3 shards
"9:6" # 9 nodes, 6 shards
"9:9" # 9 nodes, 9 shards
)

generate_kustomization() {
local node_count=$1
local shard_count=$2
local kustomization_file="kustomization.yaml"
local topology_key="${node_count}:${shard_count}"
local base_yaml=""

mkdir -p "$(dirname "$kustomization_file")"

# Validate topology
local valid_topology=false
for topology in "${VALID_TOPOLOGIES[@]}"; do
if [[ "$topology" == "$topology_key" ]]; then
valid_topology=true
break
fi
done

if ! $valid_topology; then
echo "Error: Invalid topology - ${node_count} nodes, ${shard_count} shards"
exit 1
fi

# Set base YAML based on topology
base_yaml="mongodb-sharded-${node_count}-node"
if [[ "$shard_count" -gt 1 ]]; then
base_yaml="${base_yaml}-${shard_count}-shards"
fi
base_yaml="${base_yaml}.yaml"

# Generate kustomization file
cat > "$kustomization_file" << EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./_build/root/deploy/${base_yaml}
patchesStrategicMerge:
- |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: data-db-mongodb-sharded-configsvr
spec:
volumeClaimTemplates:
- metadata:
name: datadir
annotations:
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "8Gi"
storageClassName: standard
EOF

# Add shard patches
for ((i=0; i<shard_count; i++)); do
cat >> "$kustomization_file" << EOF
- |-
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: data-db-mongodb-sharded-shard${i}-data
spec:
volumeClaimTemplates:
- metadata:
name: datadir
annotations:
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "8Gi"
storageClassName: standard
EOF
done
}
11 changes: 9 additions & 2 deletions .github/scripts/end2end/install-kind-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ MONGODB_APP_PASSWORD=datapass
MONGODB_APP_DATABASE=${ZENKO_MONGODB_DATABASE:-datadb}
MONGODB_RS_KEY=0123456789abcdef

MONGODB_SHARD_COUNT=${MONGODB_SHARD_COUNT:-1}

source "${DIR}/generate-kustomization.sh" && generate_kustomization "${NODE_COUNT:-1}" "${MONGODB_SHARD_COUNT}"

ENABLE_KEYCLOAK_HTTPS=${ENABLE_KEYCLOAK_HTTPS:-'false'}

KAFKA_CHART=banzaicloud-stable/kafka-operator
Expand Down Expand Up @@ -186,7 +190,7 @@ mongodb_wait_for_shards() {
--eval "db.runCommand({ listshards: 1 }).shards.length"
)

[ $count == "1" ]
[ $count == "$MONGODB_SHARD_COUNT" ]
}

mongodb_sharded() {
Expand All @@ -201,7 +205,10 @@ mongodb_sharded() {

kubectl rollout status statefulset data-db-mongodb-sharded-mongos
kubectl rollout status statefulset data-db-mongodb-sharded-configsvr
kubectl rollout status statefulset data-db-mongodb-sharded-shard0-data

for ((i=0; i<MONGODB_SHARD_COUNT; i++)); do
kubectl rollout status statefulset "data-db-mongodb-sharded-shard${i}-data"
done

retry mongodb_wait_for_shards "no shards found"

Expand Down
39 changes: 0 additions & 39 deletions .github/scripts/end2end/kustomization.yaml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/end2end.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,54 @@ jobs:
- name: Clean Up
run: kind delete cluster

ctst-end2end-sharded-3-shards:
needs: [build-kafka, lint-and-build-ctst]
runs-on:
- ubuntu-22.04-8core
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/install-end2end-dependencies
- name: Wait for Docker daemon to be ready
uses: ./.github/actions/wait-docker-ready
- name: Kubectl tool installer
uses: Azure/setup-kubectl@v4
- name: Login to Registry
uses: docker/login-action@v3
with:
username: "${{ github.repository_owner }}"
password: "${{ github.token }}"
registry: ghcr.io
- name: Deploy Zenko
uses: ./.github/actions/deploy
env:
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
ZENKO_ENABLE_SOSAPI: true
TIME_PROGRESSION_FACTOR: 86400
TRANSITION_ONE_DAY_EARLIER: false
EXPIRE_ONE_DAY_EARLIER: false
MONGODB_SHARD_COUNT: 2
- name: Configure E2E test environment
run: bash configure-e2e-ctst.sh
working-directory: ./.github/scripts/end2end
- name: Run CTST end to end tests
run: bash run-e2e-ctst.sh "" "" "" "" --tags 'not @PRA'
working-directory: ./.github/scripts/end2end
- name: Debug wait
uses: ./.github/actions/debug-wait
timeout-minutes: 60
if: failure() && runner.debug == '1'
- name: Archive and publish artifacts
uses: ./.github/actions/archive-artifacts
with:
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}
trunk_token: ${{ secrets.TRUNK_TOKEN }}
if: always()
- name: Clean Up
run: kind delete cluster

write-final-status:
runs-on: ubuntu-latest
needs:
Expand All @@ -654,6 +702,7 @@ jobs:
- end2end-sharded
- end2end-pra
- ctst-end2end-sharded
- ctst-end2end-sharded-3-shards
steps:
- name: Upload final status
uses: scality/actions/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions solution-base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SKOPEO_OPTS="--override-os linux --insecure-policy"
SOLUTION_REGISTRY=metalk8s-registry-from-config.invalid/${PRODUCT_LOWERNAME}-${VERSION_FULL}

MONGODB_SHARDED_SINGLE_NODE_PATH=${ISO_ROOT}/deploy/mongodb-sharded-1-node.yaml
MONGODB_SHARDED_SINGLE_NODE_TWO_SHARDS_PATH=${ISO_ROOT}/deploy/mongodb-sharded-1-node-2-shards.yaml
MONGODB_SHARDED_THREE_NODE_PATH=${ISO_ROOT}/deploy/mongodb-sharded-3-nodes.yaml
MONGODB_SHARDED_THREE_NODE_THREE_SHARDS_PATH=${ISO_ROOT}/deploy/mongodb-sharded-3-nodes-3-shards.yaml
MONGODB_SHARDED_SIX_NODE_PATH=${ISO_ROOT}/deploy/mongodb-sharded-6-nodes.yaml
Expand Down Expand Up @@ -130,6 +131,7 @@ function render_mongodb_sharded_yamls()
function mongodb_sharded_yamls()
{
render_mongodb_sharded_yamls "${MONGODB_SHARDED_SINGLE_NODE_PATH}" 1 1
render_mongodb_sharded_yamls "${MONGODB_SHARDED_SINGLE_NODE_TWO_SHARDS_PATH}" 2 1
render_mongodb_sharded_yamls "${MONGODB_SHARDED_THREE_NODE_PATH}" 1 3
render_mongodb_sharded_yamls "${MONGODB_SHARDED_THREE_NODE_THREE_SHARDS_PATH}" 3 3
render_mongodb_sharded_yamls "${MONGODB_SHARDED_SIX_NODE_PATH}" 1 6
Expand Down

0 comments on commit 7778198

Please sign in to comment.