Skip to content

Commit

Permalink
[type:feat] support e2e contain in k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
moremind committed Sep 19, 2023
1 parent 81c6696 commit d2f5b81
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
if: steps.filter.outputs.changed == 'true'
run: |
bash ./shenyu-e2e/k8s/script/init/mysql_container_init.sh
bash ./shenyu-e2e/k8s/script/init/postgres_container_init.sh
- name: Run E2E Tests
if: steps.filter.outputs.changed == 'true'
Expand Down
4 changes: 3 additions & 1 deletion shenyu-e2e/k8s/script/init/mysql_container_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ PRGDIR=`dirname "$(dirname "$curPath")"`
echo $PRGDIR
kubectl apply -f ${PRGDIR}/shenyu-mysql.yml
sleep 30s
kubectl get pod -o wide
kubectl get pod -o wide

# test mysql
35 changes: 35 additions & 0 deletions shenyu-e2e/k8s/script/init/postgres_container_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# prepare mysql
bash ./shenyu-e2e/k8s/script/storage/storage_init_postgres.sh

## todo: for test
ls /tmp/shenyu-e2e/postgres/schema
ls /tmp/shenyu-e2e/postgres/driver
## todo: for test

# init kubernetes for mysql
curPath=$(readlink -f "$(dirname "$0")")
PRGDIR=`dirname "$(dirname "$curPath")"`
echo $PRGDIR
kubectl apply -f ${PRGDIR}/shenyu-deployment-postgres.yml
sleep 30s
kubectl get pod -o wide

# test postgres
11 changes: 6 additions & 5 deletions shenyu-e2e/k8s/script/storage/storage_init_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

mkdir -p /tmp/shenyu-e2e/pg
mkdir -p /tmp/shenyu-e2e/postgres/schema
mkdir -p /tmp/shenyu-e2e/postgres/driver

cp db/init/pg/create-table.sql /tmp/shenyu-e2e/pg/create-table.sql

wget -O /tmp/shenyu-e2e/pg/postgresql.jar \
wget -O /tmp/shenyu-e2e/postgres/driver/postgresql.jar \
https://jdbc.postgresql.org/download/postgresql-42.5.0.jar || \
wget -O /tmp/shenyu-e2e/pg/postgresql.jar \
wget -O /tmp/shenyu-e2e/postgres/driver/postgresql.jar \
https://jdbc.postgresql.org/download/postgresql-42.5.0.jar

cp db/init/pg/create-table.sql /tmp/shenyu-e2e/postgres/schema/create-table.sql
98 changes: 98 additions & 0 deletions shenyu-e2e/k8s/shenyu-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
name: shenyu-postgres
labels:
app: shenyu-postgres
spec:
replicas: 1
selector:
matchLabels:
app: shenyu-postgres
template:
metadata:
labels:
app: shenyu-postgres
spec:
containers:
- name: shenyu-postgres
image: postgres:14
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: shenyue2e
- name: POSTGRES_PASSWORD
value: shenyue2e
- name: POSTGRES_DB
value: shenyu
livenessProbe:
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
exec:
command:
- /bin/sh
- "-c"
- cat < /dev/null > /dev/tcp/127.0.0.1/5432
readinessProbe:
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
exec:
command:
- /bin/sh
- "-c"
- cat < /dev/null > /dev/tcp/127.0.0.1/5432
volumeMounts:
- name: pg-data
mountPath: /var/lib/postgresql/data
- name: postgres-initdb
mountPath: /docker-entrypoint-initdb.d/initdb.sql
imagePullPolicy: Always
volumes:
- name: pg-data
hostPath:
path: /var/lib/postgresql/data
- name: postgres-initdb
hostPath:
type: FileOrCreate
path: /tmp/shenyu-e2e/postgres/schema/create-table.sql
restartPolicy: Always

---
apiVersion: v1
kind: Service
metadata:
name: shenyu-postgres
labels:
app: shenyu-postgres
spec:
type: NodePort
selector:
app: shenyu-postgres
ports:
- name: "5432"
port: 5432
targetPort: 5432
nodePort: 30432
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ sh ${curPath}/healthcheck.sh h2

curl -S "http://localhost:31195/actuator/pluginData"

admin_status=`curl -X GET "http://localhost:31095/actuator/health" -H "accept: */*"`
bootstrap_status=`curl -X GET "http://localhost:31195/actuator/health" -H "accept: */*"`
admin_status=`curl -s -o /dev/null -w "%{http_code}" -X GET "http://localhost:31095/actuator/health" -H "accept: */*"`
bootstrap_status=`curl -s -o /dev/null -w "%{http_code}" -X GET "http://localhost:31195/actuator/health" -H "accept: */*"`

if [ $admin_status -eq 200 -a $bootstrap_status -eq 200 ]; then
echo -e "Success to send request: $admin_status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
- name: spring.datasource.password
value: shenyue2e
- name: spring.datasource.url
value: jdbc:postgresql://shenyu-postgres:5432/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
value: jdbc:postgresql://shenyu-postgres:30432/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false
ports:
- containerPort: 9097
livenessProbe:
Expand All @@ -55,7 +55,7 @@ spec:
port: 9097
path: /actuator/health
readinessProbe:
initialDelaySeconds: 10
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
Expand All @@ -65,7 +65,6 @@ spec:
path: /actuator/health
imagePullPolicy: IfNotPresent
restartPolicy: Always
status: { }

---
apiVersion: apps/v1
Expand Down Expand Up @@ -103,7 +102,7 @@ spec:
port: 9197
path: /actuator/health
readinessProbe:
initialDelaySeconds: 10
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
Expand All @@ -113,7 +112,6 @@ spec:
path: /actuator/health
imagePullPolicy: IfNotPresent
restartPolicy: Always
status: { }

---
apiVersion: apps/v1
Expand Down

0 comments on commit d2f5b81

Please sign in to comment.