diff --git a/.github/scripts/deploy-greptimedb-cluster.sh b/.github/scripts/deploy-greptimedb-cluster.sh new file mode 100755 index 0000000..e1a9c27 --- /dev/null +++ b/.github/scripts/deploy-greptimedb-cluster.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash + +set -e + +DB_HOST="127.0.0.1" +DB_PORT="4002" +TABLE_NAME="greptimedb_cluster_test" + +CreateTableSQL="CREATE TABLE %s ( + ts TIMESTAMP DEFAULT current_timestamp(), + n INT, + row_id INT, + TIME INDEX (ts), + PRIMARY KEY(n) + ) + PARTITION BY RANGE COLUMNS (n) ( + PARTITION r0 VALUES LESS THAN (5), + PARTITION r1 VALUES LESS THAN (9), + PARTITION r2 VALUES LESS THAN (MAXVALUE) + )" + +InsertDataSQL="INSERT INTO %s(n, row_id) VALUES (%d, %d)" + +SelectDataSQL="SELECT * FROM %s" + +DropTableSQL="DROP TABLE %s" + +TestRowIDNum=1 + +function create_table() { + local table_name=$1 + local sql=$(printf "$CreateTableSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function insert_data() { + local table_name=$1 + local sql=$(printf "$InsertDataSQL" "$table_name" "$TestRowIDNum" "$TestRowIDNum") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function select_data() { + local table_name=$1 + local sql=$(printf "$SelectDataSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function drop_table() { + local table_name=$1 + local sql=$(printf "$DropTableSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function deploy_greptimedb_cluster() { + helm upgrade --install mycluster greptimedb-cluster -n default + + # Wait for greptimedb cluster to be ready + while true; do + PHASE=$(kubectl -n default get gtc mycluster -o jsonpath='{.status.clusterPhase}') + if [ "$PHASE" == "Running" ]; then + echo "Cluster is ready" + break + else + echo "Cluster is not ready yet: Current phase: $PHASE" + sleep 5 # wait for 5 seconds before check again + fi + done +} + +function deploy_greptimedb_operator() { + cd charts + helm upgrade --install greptimedb-operator greptimedb-operator -n default + + # Wait for greptimedb operator to be ready + kubectl rollout status --timeout=60s deployment/greptimedb-operator -n default +} + +function deploy_etcd() { + helm upgrade --install etcd oci://registry-1.docker.io/bitnamicharts/etcd \ + --set replicaCount=1 \ + --set auth.rbac.create=false \ + --set auth.rbac.token.enabled=false \ + -n default + + # Wait for etcd to be ready + kubectl rollout status --timeout=120s statefulset/etcd -n default +} + +function mysql_test_greptimedb_cluster() { + kubectl port-forward -n default svc/mycluster-frontend \ + 4000:4000 \ + 4001:4001 \ + 4002:4002 \ + 4003:4003 > /tmp/connections.out & + + sleep 5 + + create_table "$TABLE_NAME" + insert_data "$TABLE_NAME" + select_data "$TABLE_NAME" + drop_table "$TABLE_NAME" +} + +function cleanup() { + echo "Cleaning up..." + pkill -f "kubectl port-forward" +} + +function main() { + # Deploy the bitnami etcd helm chart + deploy_etcd + + # Deploy the greptimedb-operator helm chart + deploy_greptimedb_operator + + # Deploy the greptimedb-cluster helm chart + deploy_greptimedb_cluster + + # Add mysql test with greptimedb cluster + mysql_test_greptimedb_cluster + + # clean resource + cleanup +} + +main diff --git a/.github/scripts/deploy-greptimedb-standalone.sh b/.github/scripts/deploy-greptimedb-standalone.sh new file mode 100755 index 0000000..0c3153c --- /dev/null +++ b/.github/scripts/deploy-greptimedb-standalone.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +set -e + +DB_HOST="127.0.0.1" +DB_PORT="4002" +TABLE_NAME="greptimedb_standalone_test" + +CreateTableSQL="CREATE TABLE %s ( + ts TIMESTAMP DEFAULT current_timestamp(), + n INT, + row_id INT, + TIME INDEX (ts), + PRIMARY KEY(n) + ) + PARTITION BY RANGE COLUMNS (n) ( + PARTITION r0 VALUES LESS THAN (5), + PARTITION r1 VALUES LESS THAN (9), + PARTITION r2 VALUES LESS THAN (MAXVALUE) + )" + +InsertDataSQL="INSERT INTO %s(n, row_id) VALUES (%d, %d)" + +SelectDataSQL="SELECT * FROM %s" + +DropTableSQL="DROP TABLE %s" + +TestRowIDNum=1 + +function create_table() { + local table_name=$1 + local sql=$(printf "$CreateTableSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function insert_data() { + local table_name=$1 + local sql=$(printf "$InsertDataSQL" "$table_name" "$TestRowIDNum" "$TestRowIDNum") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function select_data() { + local table_name=$1 + local sql=$(printf "$SelectDataSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function drop_table() { + local table_name=$1 + local sql=$(printf "$DropTableSQL" "$table_name") + mysql -h "$DB_HOST" -P "$DB_PORT" -e "$sql" +} + +function deploy_greptimedb_standalone() { + cd charts + helm upgrade --install greptimedb-standalone greptimedb-standalone -n default + + # Wait for greptimedb standalone to be ready + kubectl rollout status --timeout=60s statefulset/greptimedb-standalone -n default +} + +function mysql_test_greptimedb_standalone() { + kubectl port-forward -n default svc/greptimedb-standalone \ + 4000:4000 \ + 4001:4001 \ + 4002:4002 \ + 4003:4003 > /tmp/connections.out & + + sleep 3 + + create_table "$TABLE_NAME" + insert_data "$TABLE_NAME" + select_data "$TABLE_NAME" + drop_table "$TABLE_NAME" +} + +function cleanup() { + echo "Cleaning up..." + pkill -f "kubectl port-forward" +} + +function main() { + # Deploy the greptimedb-standalone helm chart + deploy_greptimedb_standalone + + # Add mysql test with greptimedb standalone + mysql_test_greptimedb_standalone + + # clean resource + cleanup +} + +main diff --git a/.github/scripts/setup-e2e-env.sh b/.github/scripts/setup-e2e-env.sh new file mode 100755 index 0000000..fadfc78 --- /dev/null +++ b/.github/scripts/setup-e2e-env.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +CLUSTER=greptime-chart-e2e +REGISTRY_NAME=kind-registry +REGISTRY_PORT=5001 + +function check_prerequisites() { + if ! hash docker 2>/dev/null; then + echo "docker command is not found! You can download docker here: https://docs.docker.com/get-docker/" + exit + fi + + if ! hash kind 2>/dev/null; then + echo "kind command is not found! You can download kind here: https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries" + exit + fi + + if ! hash kubectl 2>/dev/null; then + echo "kubectl command is not found! You can download kubectl here: https://kubernetes.io/docs/tasks/tools/" + exit + fi +} + +function start_local_registry() { + # create registry container unless it already exists + if [ "$(docker inspect -f '{{.State.Running}}' "${REGISTRY_NAME}" 2>/dev/null || true)" != 'true' ]; then + docker run \ + -d --restart=always -p "127.0.0.1:${REGISTRY_PORT}:5000" --name "${REGISTRY_NAME}" \ + registry:2 + fi +} + +function create_kind_cluster() { + # check cluster + for cluster in $(kind get clusters); do + if [ "$cluster" = "${CLUSTER}" ]; then + echo "Use the existed cluster $cluster" + kubectl config use-context kind-"$cluster" + return + fi + done + + # create a cluster with the local registry enabled in containerd + cat <