Skip to content

Commit 71b3323

Browse files
committed
🔧(helm) rework chart based on jenny helm chart
Rework Warren Helm chart based on the work done on Jenny Helm chart in PR openfun/charts#5 Changes done in this commit: - Jobs for database migration or static collection are abstracted into a single job template - Env variables are now processed in the helper template - Removed unused HorizontalPodAutoscaler - Add startup probes for migration checks - Migration jobs are now executed post helm installation/upgrade - Removed unnecessary security context variables - Add a nginx container alongside warren-app to serve static files - Rework postgresql values to have a functional Helm chart on a local cluster - Update Helm chart README.md
1 parent e5f0d34 commit 71b3323

27 files changed

+667
-814
lines changed

src/helm/README.md

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -102,63 +102,30 @@ Our Elasticsearch cluster is all set. In the next section, we will now deploy
102102

103103
### Deploy the LRS: Ralph
104104

105-
Ralph is also distributed as a Helm chart that can be deployed with a single
106-
line of code:
105+
Ralph is also distributed as a Helm chart. Check out the [Ralph Helm chart README](https://github.com/openfun/ralph/blob/main/src/helm/README.md) to deploy it!
107106

108-
```bash
109-
helm install \
110-
--values charts/ralph/values.yaml \
111-
--set envSecrets.RALPH_BACKENDS__DATABASE__ES__HOSTS=https://elastic:"${ELASTIC_PASSWORD}"@data-lake-es-http:9200 \
112-
lrs oci://registry-1.docker.io/openfuncharts/ralph
113-
```
114-
115-
One can check if the server is running by opening a network tunnel to the
116-
service using the `port-forward` sub-command:
117-
118-
119-
```bash
120-
kubectl port-forward svc/lrs-ralph 8080:8080
121-
```
122-
123-
And then send a request to the server using this tunnel:
124-
125-
```bash
126-
curl --user admin:password localhost:8080/whoami
127-
```
128-
129-
We expect a valid JSON response stating about the user you are using for this
130-
request.
131-
132-
If everything went well, we can send 22k xAPI statements to the LRS using:
107+
### Deploy the dashboard suite: Warren
133108

109+
Let's create secrets needed for Warren deployment with:
134110
```bash
135-
gunzip -c ../../data/statements.jsonl.gz | \
136-
sed "s/@timestamp/timestamp/g" | \
137-
jq -s . | \
138-
curl -Lk \
139-
--user admin:password \
140-
-X POST \
141-
-H "Content-Type: application/json" \
142-
http://localhost:8080/xAPI/statements/ -d @-
111+
kubectl create secret generic warren-api-secrets --from-env-file=warren/charts/api/.secret
112+
kubectl create secret generic warren-app-secrets --from-env-file=warren/charts/app/.secret
143113
```
144114

145-
### Deploy the dashboard suite: Warren
146-
147-
Now that the LRS is running, we can deploy warren along with its dependencies
115+
We can now deploy Warren along with its dependencies
148116
using:
149117

150118
```bash
151119
# Fetch dependencies
152-
cd warren && helm dependency build
120+
helm dependency build ./warren
153121

154-
# Deploy postgresql for Warren `app` service (Django)
122+
# Install Warren
155123
helm install warren ./warren --values development.yaml --debug --atomic
156124
```
157125

158126
If you want to upgrade your deployment (after a change in a template or a
159127
value), you can upgrade deployed version using:
160128

161129
```bash
162-
# Deploy postgresql for Warren `app` service (Django)
163130
helm upgrade --install warren ./warren --values development.yaml --debug --atomic
164131
```

src/helm/charts/ralph/values.yaml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
envSecrets:
2-
RALPH_BACKENDS__DATABASE__ES__INDEX: statements
3-
RALPH_BACKENDS__DATABASE__ES__CLIENT_OPTIONS__ca_certs: "/usr/local/share/ca-certificates/ca.crt"
4-
RALPH_BACKENDS__DATABASE__ES__CLIENT_OPTIONS__verify_certs: "true"
5-
6-
lrs:
7-
auth:
8-
- username: "admin"
9-
hash: "$2b$12$JFK.YCdbUWD2rS94fT4.m.KC/fIMzUMPMtjaD4t3t1iAfqki3ZPOq"
10-
scopes: ["example_scope"]
11-
12-
elastic:
13-
enabled: true
14-
mountCACert: true
15-
caSecretName: "data-lake-es-http-certs-public"
1+
database:
2+
tls:
3+
enabled: true
4+
certificatesSecret: "data-lake-es-http-certs-public"
5+
certificatesMountPath: "/usr/local/share/ca-certificates/"

src/helm/development.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# -- Warren - app service --
44
app:
55
enabled: true
6-
allowedHosts:
7-
- "localhost"
8-
djangoConfiguration: Development
6+
django:
7+
allowedHosts:
8+
- "localhost"
9+
configuration: "Development"
910
image:
1011
pullPolicy: Always
1112
persistence:
@@ -14,7 +15,8 @@ app:
1415
# -- Warren - api service --
1516
api:
1617
enabled: true
17-
allowedHosts:
18+
fastapi:
19+
allowedHosts:
1820
- "http://localhost:8080"
1921
image:
2022
pullPolicy: Always
@@ -24,10 +26,13 @@ postgresql:
2426
enabled: true
2527
image:
2628
tag: 12.17.0-debian-11-r12
27-
28-
global:
29-
postgresql:
30-
auth:
31-
username: fun
32-
password: pass
33-
database: warren-api
29+
auth:
30+
username: fun
31+
password: pass
32+
database: warren-api
33+
primary:
34+
initdb:
35+
scripts:
36+
init.sql: |
37+
CREATE DATABASE "warren-app";
38+
GRANT ALL PRIVILEGES ON DATABASE "warren-app" TO fun;

src/helm/manifests/warren-secrets.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/helm/warren/charts/api/.secret

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
WARREN_API_DB_PASSWORD=pass
2+
WARREN_LRS_AUTH_BASIC_PASSWORD=password
3+
WARREN_APP_SIGNING_KEY=change_me

src/helm/warren/charts/api/templates/_helpers.tpl

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,62 @@ app.kubernetes.io/instance: {{ .Release.Name }}
5151
{{- end }}
5252

5353
{{/*
54-
Allowed hosts string (environment variable value)
54+
Environment variables
5555
*/}}
56-
{{- define "api.allowedHosts" -}}
57-
{{- printf "%q" .Values.allowedHosts | replace " " "," | quote -}}
56+
{{- define "api.envs" -}}
57+
- name: "WARREN_API_SERVER_PORT"
58+
value: "{{ .Values.service.port }}"
59+
- name: "WARREN_API_DB_NAME"
60+
value: "{{ .Values.fastapi.db.name }}"
61+
- name: "WARREN_API_DB_USER"
62+
value: "{{ .Values.fastapi.db.user }}"
63+
- name: "WARREN_API_DB_PASSWORD"
64+
valueFrom:
65+
secretKeyRef:
66+
name: warren-api-secrets
67+
key: WARREN_API_DB_PASSWORD
68+
- name: "WARREN_API_DB_ENGINE"
69+
value: "{{ .Values.fastapi.db.engine }}"
70+
- name: "WARREN_API_DB_HOST"
71+
value: "{{ .Values.fastapi.db.host }}"
72+
- name: "WARREN_API_DB_PORT"
73+
value: "{{ .Values.fastapi.db.port }}"
74+
- name: "WARREN_ALLOWED_HOSTS"
75+
value: {{ printf "%q" .Values.fastapi.allowedHosts | replace " " "," | quote }}
76+
- name: "WARREN_LRS_HOSTS"
77+
value: "{{ .Values.fastapi.lrs.hosts }}"
78+
- name: "WARREN_LRS_AUTH_BASIC_USERNAME"
79+
value: "{{ .Values.fastapi.lrs.username }}"
80+
- name: "WARREN_LRS_AUTH_BASIC_PASSWORD"
81+
valueFrom:
82+
secretKeyRef:
83+
name: warren-api-secrets
84+
key: WARREN_LRS_AUTH_BASIC_PASSWORD
85+
- name: "WARREN_APP_SIGNING_ALGORITHM"
86+
value: "{{ .Values.fastapi.signingAlgorithm }}"
87+
- name: "WARREN_APP_SIGNING_KEY"
88+
valueFrom:
89+
secretKeyRef:
90+
name: warren-api-secrets
91+
key: WARREN_APP_SIGNING_KEY
92+
{{- range $key, $val := .Values.env.secret }}
93+
- name: {{ $val.envName }}
94+
valueFrom:
95+
secretKeyRef:
96+
name: {{ $val.secretName }}
97+
key: {{ $val.keyName }}
98+
{{- end }}
99+
{{- end }}
100+
101+
{{/*
102+
ImagePullSecrets
103+
*/}}
104+
{{- define "fastapi.imagePullSecrets" -}}
105+
{{- $pullSecrets := .Values.imagePullSecrets }}
106+
{{- if (not (empty $pullSecrets)) }}
107+
imagePullSecrets:
108+
{{- range $pullSecrets }}
109+
- name: {{ . }}
110+
{{ end }}
111+
{{- end -}}
58112
{{- end }}

src/helm/warren/charts/api/templates/cm_logging.yaml renamed to src/helm/warren/charts/api/templates/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: "{{ .Values.loggingConfigConfigMap }}"
4+
name: "{{ template "api.fullname" . }}-logging-config"
55
labels:
66
{{- include "api.labels" . | nindent 4 }}
77
data:

src/helm/warren/charts/api/templates/deployment.yaml

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: {{ include "api.fullname" . }}
5+
namespace: {{ .Release.Namespace | quote }}
56
labels:
67
{{- include "api.labels" . | nindent 4 }}
78
spec:
8-
{{- if not .Values.autoscaling.enabled }}
9-
replicas: {{ .Values.replicaCount }}
10-
{{- end }}
119
selector:
1210
matchLabels:
1311
{{- include "api.selectorLabels" . | nindent 6 }}
12+
{{- if not .Values.autoscaling.enabled }}
13+
replicas: {{ .Values.replicaCount }}
14+
{{- end }}
1415
template:
1516
metadata:
1617
{{- with .Values.podAnnotations }}
@@ -19,72 +20,48 @@ spec:
1920
{{- end }}
2021
labels:
2122
{{- include "api.labels" . | nindent 8 }}
22-
{{- with .Values.podLabels }}
23-
{{- toYaml . | nindent 8 }}
24-
{{- end }}
2523
spec:
26-
{{- with .Values.imagePullSecrets }}
27-
imagePullSecrets:
28-
{{- toYaml . | nindent 8 }}
29-
{{- end }}
30-
securityContext:
31-
{{- toYaml .Values.podSecurityContext | nindent 8 }}
24+
{{- include "fastapi.imagePullSecrets" . | nindent 6 }}
3225
containers:
33-
- name: {{ .Chart.Name }}
34-
securityContext:
35-
{{- toYaml .Values.securityContext | nindent 12 }}
26+
- name: "{{ .Chart.Name }}-fastapi"
3627
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3728
imagePullPolicy: {{ .Values.image.pullPolicy }}
38-
ports:
39-
- name: http
40-
containerPort: {{ .Values.service.port }}
41-
protocol: TCP
29+
resources:
30+
{{- toYaml .Values.resources | nindent 12 }}
4231
livenessProbe:
4332
httpGet:
4433
path: /__heartbeat__
4534
port: http
46-
httpHeaders:
47-
- name: Host
48-
value: '{{ first .Values.allowedHosts | trimPrefix "https://" }}'
4935
initialDelaySeconds: 15
5036
periodSeconds: 30
5137
readinessProbe:
5238
httpGet:
5339
path: /__lbheartbeat__
5440
port: http
55-
httpHeaders:
56-
- name: Host
57-
value: '{{ first .Values.allowedHosts | trimPrefix "https://" }}'
5841
initialDelaySeconds: 5
5942
periodSeconds: 5
43+
startupProbe:
44+
exec:
45+
command:
46+
- "bash"
47+
- "-c"
48+
- "warren migration check"
49+
initialDelaySeconds: 5
50+
periodSeconds: 5
51+
timeoutSeconds: 120
6052
env:
61-
- name: WARREN_API_SERVER_PORT
62-
value: "{{ .Values.service.port }}"
63-
- name: WARREN_API_DB_ENGINE
64-
value: {{ .Values.database.engine }}
65-
- name: WARREN_API_DB_PORT
66-
value: {{ .Values.database.port | quote }}
67-
- name: WARREN_APP_SIGNING_ALGORITHM
68-
value: {{ .Values.signingAlgorithm }}
69-
- name: WARREN_ALLOWED_HOSTS
70-
value: {{ include "api.allowedHosts" . }}
71-
envFrom:
72-
- secretRef:
73-
name: {{ .Values.envVarsSecret | quote }}
74-
{{ with .Values.podCommand }}
53+
{{- include "api.envs" . | nindent 12 }}
54+
{{ with .Values.fastapi.command }}
7555
command:
7656
{{- toYaml . | nindent 12 }}
7757
{{- end }}
78-
resources:
79-
{{- toYaml .Values.resources | nindent 12 }}
80-
{{- with .Values.volumeMounts }}
8158
volumeMounts:
82-
{{- toYaml . | nindent 12 }}
83-
{{- end }}
84-
{{- with .Values.volumes }}
59+
- name: logging-config
60+
mountPath: "/etc/warren/api"
8561
volumes:
86-
{{- toYaml . | nindent 8 }}
87-
{{- end }}
62+
- name: logging-config
63+
configMap:
64+
name: "warren-api-logging-config"
8865
{{- with .Values.nodeSelector }}
8966
nodeSelector:
9067
{{- toYaml . | nindent 8 }}

src/helm/warren/charts/api/templates/hpa.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)