-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add e2e * feat: add test scripts * chore: add wait ready timeout
- Loading branch information
1 parent
a710c67
commit b326eb4
Showing
5 changed files
with
347 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOF | kind create cluster --name "${CLUSTER}" --config=- | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
containerdConfigPatches: | ||
- |- | ||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${REGISTRY_PORT}"] | ||
endpoint = ["http://${REGISTRY_NAME}:5000"] | ||
nodes: | ||
- role: control-plane | ||
- role: worker | ||
- role: worker | ||
EOF | ||
|
||
# connect the registry to the cluster network if not already connected | ||
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${REGISTRY_NAME}")" = 'null' ]; then | ||
docker network connect "kind" "${REGISTRY_NAME}" | ||
fi | ||
|
||
# Document the local registry | ||
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: local-registry-hosting | ||
namespace: kube-public | ||
data: | ||
localRegistryHosting.v1: | | ||
host: "localhost:${REGISTRY_PORT}" | ||
help: "https://kind.sigs.k8s.io/docs/user/local-registry/" | ||
EOF | ||
} | ||
|
||
check_prerequisites | ||
start_local_registry | ||
create_kind_cluster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: E2E Test | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
chart: | ||
type: choice | ||
description: Chart Name | ||
required: true | ||
options: | ||
- greptimedb-cluster | ||
- greptimedb-standalone | ||
|
||
jobs: | ||
e2e: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Helm | ||
uses: azure/setup-helm@v3 | ||
with: | ||
version: v3.12.1 | ||
|
||
- name: Setup e2e environment | ||
shell: bash | ||
run: | | ||
.github/scripts/setup-e2e-env.sh | ||
- name: Deploy greptimedb-cluster chart | ||
if: ${{ github.event.inputs.chart == 'greptimedb-cluster' }} | ||
shell: bash | ||
run: | | ||
.github/scripts/deploy-greptimedb-cluster.sh | ||
- name: Deploy greptimedb-standalone chart | ||
if: ${{ github.event.inputs.chart == 'greptimedb-standalone' }} | ||
shell: bash | ||
run: | | ||
.github/scripts/deploy-greptimedb-standalone.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,12 @@ jobs: | |
- name: Install Helm | ||
uses: azure/setup-helm@v3 | ||
with: | ||
version: v3.10.0 | ||
version: v3.12.1 | ||
|
||
- name: Run chart-releaser | ||
uses: helm/[email protected] | ||
uses: helm/[email protected] | ||
with: | ||
charts_dir: charts | ||
env: | ||
CR_SKIP_EXISTING: true | ||
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
|