Skip to content

Commit

Permalink
test: add e2e test for xline pvc
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Dec 23, 2023
1 parent d298ebd commit 2efe3f9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/e2e/cases/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _TEST_CI_SECRET_NAME="auth-cred"
_TEST_CI_NAMESPACE="default"
_TEST_CI_DNS_SUFFIX="svc.cluster.local"
_TEST_CI_XLINE_PORT="2379"
_TEST_CI_STORAGECLASS_NAME="e2e-storage"
_TEST_CI_LOG_SYNC_TIMEOUT=60

function test::ci::_mk_endpoints() {
Expand Down Expand Up @@ -117,6 +118,22 @@ function test::ci::wait_all_xline_pod_ready() {
done
}

function test::ci::_prepare_pv() {
log::info "create persistent volume and storage class"
mkdir -p /tmp/host-500m-pv1 /tmp/host-500m-pv2 /tmp/host-500m-pv3
k8s::kubectl apply -f "$(dirname "${BASH_SOURCE[0]}")/manifests/e2e-storage.yaml" >/dev/null 2>&1
k8s::kubectl::wait_resource_creation storageclass $_TEST_CI_STORAGECLASS_NAME
k8s::kubectl::wait_resource_creation pv "host-500m-pv1"
k8s::kubectl::wait_resource_creation pv "host-500m-pv2"
k8s::kubectl::wait_resource_creation pv "host-500m-pv3"
}

function test::ci::_clean_pv() {
log::info "delete persistent volume and storage class"
k8s::kubectl delete -f "$(dirname "${BASH_SOURCE[0]}")/manifests/e2e-storage.yaml" >/dev/null 2>&1
rm -rf /tmp/host-500m-pv1 /tmp/host-500m-pv2 /tmp/host-500m-pv3
}

function test::ci::_start() {
log::info "starting controller"
pushd $(dirname "${BASH_SOURCE[0]}")/../../../
Expand All @@ -127,6 +144,7 @@ function test::ci::_start() {
log::info "create xline auth key pairs"
k8s::kubectl apply -f "$(dirname "${BASH_SOURCE[0]}")/manifests/auth-cred.yaml" >/dev/null 2>&1
k8s::kubectl::wait_resource_creation secret $_TEST_CI_SECRET_NAME
test::ci::_prepare_pv
log::info "starting xline cluster"
k8s::kubectl apply -f "$(dirname "${BASH_SOURCE[0]}")/manifests/cluster.yaml" >/dev/null 2>&1
k8s::kubectl::wait_resource_creation sts $_TEST_CI_STS_NAME
Expand All @@ -136,10 +154,13 @@ function test::ci::_teardown() {
log::info "stopping controller"
pushd $(dirname "${BASH_SOURCE[0]}")/../../../
test::ci::_uninstall_CRD
controller_pid=$(ps aux | grep "[g]o run ./cmd/main.go" | awk '{print $2}')
controller_pid=$(lsof -i:8081 | awk 'NR==2 {print $2}')
if [ -n "$controller_pid" ]; then
kill -9 $controller_pid
fi
k8s::kubectl delete -f "$(dirname "${BASH_SOURCE[0]}")/manifests/cluster.yaml" >/dev/null 2>&1
k8s::kubectl delete -f "$(dirname "${BASH_SOURCE[0]}")/manifests/auth-cred.yaml" >/dev/null 2>&1
test::ci::_clean_pv
}

function test::ci::_chaos() {
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/cases/manifests/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ spec:
image: phoenix500526/xline
imagePullPolicy: IfNotPresent
replicas: 3
storageClassName: "e2e-storage"
requests:
storage: 500Mi
authSecret:
name: auth-cred
mountPath: /tmp/auth-cred
Expand Down
51 changes: 51 additions & 0 deletions tests/e2e/cases/manifests/e2e-storage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: "e2e-storage"
provisioner: "kubernetes.io/no-provisioner"

---
apiVersion: v1
kind: PersistentVolume
metadata:
name: host-500m-pv1

spec:
storageClassName: e2e-storage
accessModes:
- ReadWriteOnce
capacity:
storage: 500Mi
hostPath:
path: /tmp/host-500m-pv1/
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: host-500m-pv2

spec:
storageClassName: e2e-storage
accessModes:
- ReadWriteOnce
capacity:
storage: 500Mi
hostPath:
path: /tmp/host-500m-pv2/
---

apiVersion: v1
kind: PersistentVolume
metadata:
name: host-500m-pv3

spec:
storageClassName: e2e-storage
accessModes:
- ReadWriteOnce
capacity:
storage: 500Mi
hostPath:
path: /tmp/host-500m-pv3/
---

0 comments on commit 2efe3f9

Please sign in to comment.