Skip to content

Commit

Permalink
Helm tests for HA deployment (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
as51340 authored Jul 16, 2024
1 parent 18d10a8 commit 0a0702c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 50 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/lint-test-high-availability.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint and Test Charts
name: Lint and Test Charts High Availability

on:
pull_request:
Expand Down Expand Up @@ -39,7 +39,6 @@ jobs:
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
continue-on-error: true

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
Expand Down Expand Up @@ -77,5 +76,4 @@ jobs:
- name: Run Helm tests
if: steps.list-changed.outputs.changed == 'true'
run: |
helm test mem-ha-test
kubectl logs -l app=memgraph
timeout 30 helm test mem-ha-test # If connection to some port is broken, this will timeout with code 124
2 changes: 1 addition & 1 deletion charts/memgraph-high-availability/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: memgraph-high-availability
description: A Helm chart for Kubernetes with Memgraph High availabiliy capabilites

version: 0.1.1
version: 0.1.2
appVersion: "2.18.0"

type: application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,47 @@ spec:
template:
metadata:
labels:
app: memgraph
app: memgraph-ha-test-cluster-setup
spec:
containers:
- name: memgraph-test-cluster-setup
image: memgraph/memgraph:2.17.0
image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}"
command: ["/bin/bash", "-c"]
args:
- |
echo "Running cluster test setup..."
result=$(echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687)
echo "$result"
instances=$(echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687)
echo "$instances"
num_leaders=$(echo "$instances" | grep -c "leader")
if [ $num_leaders -ne 1 ]; then
echo "Expected 1 leader after registration, got $num_leaders."
exit 1
fi
num_followers=$(echo "$instances" | grep -c "follower")
if [ $num_followers -ne 2 ]; then
echo "Expected 2 followers after registration, got $num_followers."
exit 1
fi
num_mains=$(echo "$instances" | grep -c "main")
if [ $num_mains -ne 1 ]; then
echo "Expected 1 main after registration, got $num_mains."
exit 1
fi
num_replicas=$(echo "$instances" | grep -c "replica")
if [ $num_replicas -ne 1 ]; then
echo "Expected 1 replica after registration, got $num_replicas."
exit 1
fi
num_instances_down=$(echo "instances" | grep -c "down")
if [ $num_instances_down -ne 0 ]; then
echo "Expected 0 instances down after registration, got $num_instances_down."
exit 1
fi
exit 0
# Use awk to check if all instances have health status "up" and there are exactly 5 instances
echo "$result" | awk '
BEGIN {
FS = "|"
instance_count = 0
health_ok = 1
}
NR > 3 && NR <= 8 {
gsub(/^ *| *$/, "", $6) # Trim spaces from health
health = $6
print "Health: [" health "]" # Debug print
instance_count++
if (health != "up") {
health_ok = 0
print "Non-up health found: [" health "]" # Debug print
}
}
END {
print "Instance count: " instance_count # Debug print
print "Health OK: " health_ok # Debug print
if (instance_count == 5 && health_ok == 1) {
print "All instances are up and there are exactly 5 instances."
} else {
print "Check failed. Either not all instances are up or the count is not 5."
}
}
'
restartPolicy: Never
backoffLimit: 3
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Inspect logs of this test with kubectl logs -l app=memgraph-ha-test-connection
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -8,22 +9,31 @@ metadata:
"helm.sh/hook": test
spec:
template:
metadata:
labels:
app: memgraph-ha-test-connection
spec:
containers:
- name: memgraph-test
image: memgraph/memgraph:2.17.0
command: ["/bin/sh", "-c"]
image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}"
command: ["/bin/bash", "-c"]
args:
- |
echo "Running connection test on data instances..."
echo "RETURN 0;" | mgconsole --host memgraph-data-0.default.svc.cluster.local --port 7687
echo "RETURN 0;" | mgconsole --host memgraph-data-1.default.svc.cluster.local --port 7687
echo "Running a connection test on coordinator instances..."
echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-2.default.svc.cluster.local --port 7687
echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-3.default.svc.cluster.local --port 7687
commands=(
"echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687"
"echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-2.default.svc.cluster.local --port 7687"
"echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-3.default.svc.cluster.local --port 7687"
"echo 'RETURN 0;' | mgconsole --host memgraph-data-0.default.svc.cluster.local --port 7687"
"echo 'RETURN 0;' | mgconsole --host memgraph-data-1.default.svc.cluster.local --port 7687"
)
for command in "${commands[@]}"; do
echo "Running command: $command"
eval $command
if [ $? -ne 0 ]; then
echo "Command failed: $command"
exit 1
fi
done
exit 0
restartPolicy: Never
backoffLimit: 3
1 change: 0 additions & 1 deletion charts/memgraph-high-availability/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ memgraph:
logPVCSize: "256Mi"



data:
- id: "0"
boltPort: 7687
Expand Down

0 comments on commit 0a0702c

Please sign in to comment.