Skip to content

Commit c2d8dbc

Browse files
committed
PEER-244,245: Add collab service and initContainer for matching service
Signed-off-by: SeeuSim <[email protected]>
1 parent 583e3e6 commit c2d8dbc

File tree

5 files changed

+171
-6
lines changed

5 files changed

+171
-6
lines changed

backend/collaboration/.env.compose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
EXPRESS_PORT=9003
55
EXPRESS_DB_HOST="collab-db"
6-
EXPRESS_DB_PORT=5435
6+
EXPRESS_DB_PORT=5432
77
POSTGRES_DB="collab"
88
POSTGRES_USER="peerprep-collab-express"
99
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"

k8s/04-collab-svc-deployment.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: collab-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: collab-service
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
project: peerprep
14+
peerprep.service: collab-service
15+
strategy:
16+
type: Recreate
17+
template:
18+
metadata:
19+
labels:
20+
project: peerprep
21+
peerprep.service: collab-service
22+
peerprep.network.collab-api: "true"
23+
peerprep.network.collab-db: "true"
24+
spec:
25+
initContainers:
26+
- name: wait-for-postgres
27+
image: postgres:16.4
28+
env:
29+
- name: PGHOST
30+
valueFrom:
31+
secretKeyRef:
32+
name: collaboration-secret
33+
key: EXPRESS_DB_HOST
34+
- name: PGPORT
35+
valueFrom:
36+
secretKeyRef:
37+
name: collaboration-secret
38+
key: EXPRESS_DB_PORT
39+
- name: PGPASSWORD
40+
valueFrom:
41+
secretKeyRef:
42+
name: collaboration-secret
43+
key: POSTGRES_PASSWORD
44+
- name: PGUSER
45+
valueFrom:
46+
secretKeyRef:
47+
name: collaboration-secret
48+
key: POSTGRES_USER
49+
- name: PGDATABASE
50+
valueFrom:
51+
secretKeyRef:
52+
name: collaboration-secret
53+
key: POSTGRES_DB
54+
command:
55+
- /bin/sh
56+
- -c
57+
- |
58+
while ! psql -c 'SELECT 1' > /dev/null 2>&1; do
59+
echo "Waiting for $PGDATABASE"
60+
sleep 1
61+
done
62+
echo "$PGDATABASE is ready!"
63+
64+
containers:
65+
- name: collab-express
66+
image: ay2425s1cs3219g16/collab-express:main
67+
imagePullPolicy: IfNotPresent
68+
envFrom:
69+
- secretRef:
70+
name: collaboration-secret
71+
env:
72+
# When load testing, it exposes port 80 by default.
73+
- name: LOAD_TEST_POD
74+
value: http://collab-service-load-test
75+
- name: PEERPREP_UI_HOST
76+
value: http://frontend
77+
livenessProbe:
78+
exec:
79+
command:
80+
- /bin/sh
81+
- -c
82+
- wget --no-verbose --tries=1 --spider http://localhost:9003/health || exit 1
83+
periodSeconds: 30
84+
initialDelaySeconds: 5
85+
timeoutSeconds: 10
86+
failureThreshold: 5
87+
ports:
88+
- name: collab-svc-ctr
89+
containerPort: 9003
90+
resources:
91+
requests:
92+
cpu: 500m
93+
memory: 512Mi
94+
limits:
95+
cpu: "1"
96+
memory: 1Gi
97+

k8s/04-collab-svc-hpa.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: autoscaling/v2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
name: collab-service-hpa
5+
namespace: peerprep
6+
spec:
7+
scaleTargetRef:
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
name: collab-service
11+
minReplicas: 1
12+
maxReplicas: 5
13+
metrics:
14+
- type: Resource
15+
resource:
16+
name: cpu
17+
target:
18+
type: Utilization
19+
averageUtilization: 30

k8s/04-collab-svc-service.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: collab-service
5+
namespace: peerprep
6+
labels:
7+
project: peerprep
8+
peerprep.service: collab-service
9+
spec:
10+
type: ClusterIP
11+
selector:
12+
project: peerprep
13+
peerprep.service: collab-service
14+
ports:
15+
- name: collab-svc-prt
16+
port: 9003
17+
targetPort: collab-svc-ctr

k8s/04-match-svc-deployment.yaml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ spec:
2121
peerprep.service: matching-service
2222
peerprep.network.match-api: "true"
2323
peerprep.network.match-db: "true"
24+
peerprep.network.user-api: "true"
25+
peerprep.network.question-api: "true"
26+
peerprep.network.collab-api: "true"
2427
spec:
2528
initContainers:
26-
- name: wait-for-redis
29+
- name: wait-for-services
2730
image: redis:alpine
2831
env:
2932
- name: MATCHING_DB_USER
@@ -38,15 +41,38 @@ spec:
3841
key: MATCHING_DB_PASSWORD
3942
- name: MATCHING_DB_HOST
4043
value: match-db
44+
- name: PEERPREP_USER_HOST
45+
value: http://user-service:9001
46+
- name: PEERPREP_QUESTION_HOST
47+
value: http://question-service:9002
48+
- name: PEERPREP_COLLAB_HOST
49+
value: http://collab-service:9003
4150
command:
4251
- /bin/sh
4352
- -c
4453
- |
4554
until REDISCLI_AUTH="$MATCHING_DB_PASSWORD" redis-cli -h "$MATCHING_DB_HOST" --user "$MATCHING_DB_USERNAME" ping; do
4655
echo "Waiting for Redis to be ready..."
47-
sleep 1
48-
done
49-
echo "Redis is Healthy"
56+
sleep 2
57+
done &
58+
59+
until wget --no-verbose --tries=1 --spider "$PEERPREP_USER_HOST/health"; do
60+
echo "Waiting for User Service"
61+
sleep 2
62+
done &
63+
64+
until wget --no-verbose --tries=1 --spider "$PEERPREP_QUESTION_HOST/health"; do
65+
echo "Waiting for Question Service"
66+
sleep 2
67+
done &
68+
69+
until wget --no-verbose --tries=1 --spider "$PEERPREP_COLLAB_HOST/health"; do
70+
echo "Waiting for Collaboration Service"
71+
sleep 2
72+
done &
73+
74+
wait
75+
echo "All services healthy"
5076

5177
containers:
5278
- name: match-express
@@ -62,6 +88,12 @@ spec:
6288
value: "6379"
6389
- name: PEERPREP_UI_HOST
6490
value: http://frontend:3000
91+
- name: PEERPREP_USER_HOST
92+
value: http://user-service:9001
93+
- name: PEERPREP_QUESTION_HOST
94+
value: http://question-service:9002
95+
- name: PEERPREP_COLLAB_HOST
96+
value: http://collab-service:9003
6597
livenessProbe:
6698
exec:
6799
command:
@@ -80,6 +112,6 @@ spec:
80112
cpu: 500m
81113
memory: 512Mi
82114
limits:
83-
cpu: 1
115+
cpu: "1"
84116
memory: 1Gi
85117

0 commit comments

Comments
 (0)