diff --git a/tests/e2e/cases/ci.sh b/tests/e2e/cases/ci.sh index e0fead94..50f84c0d 100644 --- a/tests/e2e/cases/ci.sh +++ b/tests/e2e/cases/ci.sh @@ -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() { @@ -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]}")/../../../ @@ -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 @@ -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() { diff --git a/tests/e2e/cases/manifests/cluster.yaml b/tests/e2e/cases/manifests/cluster.yaml index 3611a03e..dd991d52 100644 --- a/tests/e2e/cases/manifests/cluster.yaml +++ b/tests/e2e/cases/manifests/cluster.yaml @@ -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 diff --git a/tests/e2e/cases/manifests/e2e-storage.yaml b/tests/e2e/cases/manifests/e2e-storage.yaml new file mode 100644 index 00000000..09a4dd15 --- /dev/null +++ b/tests/e2e/cases/manifests/e2e-storage.yaml @@ -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/ +---