Skip to content

Commit

Permalink
test: add k8s e2e test (#270)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Nov 13, 2023
1 parent af92ea6 commit 86bbe4e
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 41 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ console/atest-ui/dist
.git/
bin/
dist/
.vscode/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test-operator:
test-all-backend: test test-collector test-store-orm test-store-s3 test-store-git test-store-etcd
test-all: test-all-backend test-ui
test-e2e:
cd extensions/e2e && ./start.sh
cd e2e && ./start.sh && ./start.sh compose-k8s.yaml
install-precheck:
cp .github/pre-commit .git/hooks/pre-commit

Expand Down
12 changes: 12 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ghcr.io/linuxsuren/api-testing:master

WORKDIR /workspace
COPY e2e/* .
COPY helm/api-testing api-testing
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
RUN chmod 700 get_helm.sh
RUN ./get_helm.sh
RUN chmod +x entrypoint.sh
RUN chmod +x k8s.sh

CMD [ "/workspace/entrypoint.sh" ]
69 changes: 69 additions & 0 deletions e2e/compose-k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.1'
services:
testing:
build:
context: ..
dockerfile: e2e/Dockerfile
command: [ "/workspace/k8s.sh" ]
depends_on:
server:
condition: service_started
links:
- server
- agent
volumes:
- k8s:/root/.kube

server:
image: "rancher/k3s:${K3S_VERSION:-v1.25.15-k3s2}"
command: server
tmpfs:
- /run
- /var/run
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
privileged: true
restart: always
environment:
- K3S_TOKEN=abcd
- K3S_KUBECONFIG_OUTPUT=/output/config
- K3S_KUBECONFIG_MODE=666
volumes:
- k8s:/output
# This is just so that we get the kubeconfig file out
# - .:/output
ports:
- 30000:30000
# - 6443:6443 # Kubernetes API Server
# - 80:80 # Ingress controller port 80
# - 443:443 # Ingress controller port 443
healthcheck:
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6443"]
interval: 3s
timeout: 30s
retries: 10
start_period: 3s

agent:
image: "rancher/k3s:${K3S_VERSION:-v1.25.15-k3s2}"
tmpfs:
- /run
- /var/run
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
privileged: true
restart: always
environment:
- K3S_URL=https://server:6443
- K3S_TOKEN=abcd
links:
- server

volumes:
k8s: {}
File renamed without changes.
File renamed without changes.
14 changes: 10 additions & 4 deletions extensions/e2e/git.yaml → e2e/git.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
# https://docs.gitlab.com/ee/api/api_resources.html
name: atest
api: |
{{default "http://localhost:8080/server.Runner" (env "SERVER")}}
{{default "http://localhost:8080" (env "SERVER")}}/server.Runner
param:
server: |
{{default "http://localhost:8080" (env "SERVER")}}
items:
- name: CreateStore
- name: healthz
before:
items:
- httpReady("http://localhost:8080/healthz", 2400)
- httpReady("{{.param.server}}/healthz", 6000)
request:
api: |
{{default "http://localhost:8080" (env "SERVER")}}/healthz
- name: CreateStore
request:
api: /CreateStore
method: POST
Expand All @@ -20,7 +27,6 @@ items:
"name": "atest-store-git"
}
}
- name: listSuite
before:
items:
Expand Down
14 changes: 14 additions & 0 deletions e2e/k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

sleep 6
echo "Running k8s.sh"
helm install --kube-apiserver https://server:6443 --kube-token abcd --kube-insecure-skip-tls-verify \
api-testing ./api-testing \
--set service.type=NodePort \
--set service.nodePort=30000 \
--set persistence.enabled=false \
--set image.repository=linuxsuren.docker.scarf.sh/linuxsuren/api-testing \
--set image.tag=master

SERVER=http://server:30000 atest run -p git.yaml
31 changes: 31 additions & 0 deletions e2e/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

file=$1
if [ "$file" == "" ]
then
file=compose.yaml
fi

docker-compose version
docker-compose -f "$file" up --build -d

while true
do
docker-compose -f "$file" ps | grep testing
if [ $? -eq 1 ]
then
code=-1
docker-compose -f "$file" logs | grep e2e-testing
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
if [ $? -eq 1 ]
then
code=0
echo "successed"
fi

docker-compose -f "$file" down
set -e
exit $code
fi
sleep 1
done
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
# https://docs.gitlab.com/ee/api/api_resources.html
name: atest
api: |
{{default "http://localhost:8080/server.Runner" (env "SERVER")}}
{{default "http://localhost:8080" (env "SERVER")}}/server.Runner
param:
suiteName: "{{randAlpha 6}}"
caseName: "{{randAlpha 6}}"
store: "{{randAlpha 3}}"
server: |
{{default "http://localhost:8080" (env "SERVER")}}
items:
- name: CreateStore
before:
items:
- httpReady("http://localhost:8080/healthz", 2400)
- httpReady("{{.param.server}}/healthz", 2400)
request:
api: /CreateStore
method: POST
Expand Down
7 changes: 0 additions & 7 deletions extensions/e2e/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions extensions/e2e/start.sh

This file was deleted.

4 changes: 2 additions & 2 deletions helm/api-testing/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ spec:
protocol: TCP
livenessProbe:
httpGet:
path: /
path: /healthz
port: http
readinessProbe:
httpGet:
path: /
path: /healthz
port: http
volumeMounts:
- name: data
Expand Down

0 comments on commit 86bbe4e

Please sign in to comment.