Skip to content

Commit

Permalink
🔧(helm) rework chart based on jenny helm chart
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wilbrdt committed May 17, 2024
1 parent e5f0d34 commit 3957581
Show file tree
Hide file tree
Showing 28 changed files with 681 additions and 814 deletions.
14 changes: 14 additions & 0 deletions src/frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"

"@babel/runtime@^7.12.5":
version "7.24.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.5.tgz#230946857c053a36ccc66e1dd03b17dd0c4ed02c"
integrity sha512-Nms86NXrsaeU9vbBJKni6gXiEXZ4CVpYVzEjDH9Sb8vmZ3UljyA1GSOJl/6LGPO8EHLuSF9H+IxNXHPX8QHJ4g==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.20.1", "@babel/runtime@^7.5.5":
version "7.23.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.6.tgz#c05e610dc228855dc92ef1b53d07389ed8ab521d"
Expand Down Expand Up @@ -5441,6 +5448,13 @@ [email protected]:
loose-envify "^1.1.0"
scheduler "^0.23.0"

[email protected]:
version "4.0.13"
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-4.0.13.tgz#80386b7b27b1131c5fbb7368b8c0d983354c7947"
integrity sha512-b6PwbdSv8XeOSYvjt8LpgpKrZ0yGdtZokYwkwV2wlcZbxgopHX/hgPl5VgpnoVOWd868n1hktM8Qm4b+02MiLQ==
dependencies:
"@babel/runtime" "^7.12.5"

react-is@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down
49 changes: 8 additions & 41 deletions src/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,63 +102,30 @@ Our Elasticsearch cluster is all set. In the next section, we will now deploy

### Deploy the LRS: Ralph

Ralph is also distributed as a Helm chart that can be deployed with a single
line of code:
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!

```bash
helm install \
--values charts/ralph/values.yaml \
--set envSecrets.RALPH_BACKENDS__DATABASE__ES__HOSTS=https://elastic:"${ELASTIC_PASSWORD}"@data-lake-es-http:9200 \
lrs oci://registry-1.docker.io/openfuncharts/ralph
```

One can check if the server is running by opening a network tunnel to the
service using the `port-forward` sub-command:


```bash
kubectl port-forward svc/lrs-ralph 8080:8080
```

And then send a request to the server using this tunnel:

```bash
curl --user admin:password localhost:8080/whoami
```

We expect a valid JSON response stating about the user you are using for this
request.

If everything went well, we can send 22k xAPI statements to the LRS using:
### Deploy the dashboard suite: Warren

Let's create secrets needed for Warren deployment with:
```bash
gunzip -c ../../data/statements.jsonl.gz | \
sed "s/@timestamp/timestamp/g" | \
jq -s . | \
curl -Lk \
--user admin:password \
-X POST \
-H "Content-Type: application/json" \
http://localhost:8080/xAPI/statements/ -d @-
kubectl create secret generic warren-api-secrets --from-env-file=warren/charts/api/.secret
kubectl create secret generic warren-app-secrets --from-env-file=warren/charts/app/.secret
```

### Deploy the dashboard suite: Warren

Now that the LRS is running, we can deploy warren along with its dependencies
We can now deploy Warren along with its dependencies
using:

```bash
# Fetch dependencies
cd warren && helm dependency build
helm dependency build ./warren

# Deploy postgresql for Warren `app` service (Django)
# Install Warren
helm install warren ./warren --values development.yaml --debug --atomic
```

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

```bash
# Deploy postgresql for Warren `app` service (Django)
helm upgrade --install warren ./warren --values development.yaml --debug --atomic
```
20 changes: 5 additions & 15 deletions src/helm/charts/ralph/values.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
envSecrets:
RALPH_BACKENDS__DATABASE__ES__INDEX: statements
RALPH_BACKENDS__DATABASE__ES__CLIENT_OPTIONS__ca_certs: "/usr/local/share/ca-certificates/ca.crt"
RALPH_BACKENDS__DATABASE__ES__CLIENT_OPTIONS__verify_certs: "true"

lrs:
auth:
- username: "admin"
hash: "$2b$12$JFK.YCdbUWD2rS94fT4.m.KC/fIMzUMPMtjaD4t3t1iAfqki3ZPOq"
scopes: ["example_scope"]

elastic:
enabled: true
mountCACert: true
caSecretName: "data-lake-es-http-certs-public"
database:
tls:
enabled: true
certificatesSecret: "data-lake-es-http-certs-public"
certificatesMountPath: "/usr/local/share/ca-certificates/"
27 changes: 16 additions & 11 deletions src/helm/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# -- Warren - app service --
app:
enabled: true
allowedHosts:
- "localhost"
djangoConfiguration: Development
django:
allowedHosts:
- "localhost"
configuration: "Development"
image:
pullPolicy: Always
persistence:
Expand All @@ -14,7 +15,8 @@ app:
# -- Warren - api service --
api:
enabled: true
allowedHosts:
fastapi:
allowedHosts:
- "http://localhost:8080"
image:
pullPolicy: Always
Expand All @@ -24,10 +26,13 @@ postgresql:
enabled: true
image:
tag: 12.17.0-debian-11-r12

global:
postgresql:
auth:
username: fun
password: pass
database: warren-api
auth:
username: fun
password: pass
database: warren-api
primary:
initdb:
scripts:
init.sql: |
CREATE DATABASE "warren-app";
GRANT ALL PRIVILEGES ON DATABASE "warren-app" TO fun;
29 changes: 0 additions & 29 deletions src/helm/manifests/warren-secrets.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions src/helm/warren/charts/api/.secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WARREN_API_DB_PASSWORD=pass
WARREN_LRS_AUTH_BASIC_PASSWORD=password
WARREN_APP_SIGNING_KEY=change_me
60 changes: 57 additions & 3 deletions src/helm/warren/charts/api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,62 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Allowed hosts string (environment variable value)
Environment variables
*/}}
{{- define "api.allowedHosts" -}}
{{- printf "%q" .Values.allowedHosts | replace " " "," | quote -}}
{{- define "api.envs" -}}
- name: "WARREN_API_SERVER_PORT"
value: "{{ .Values.service.port }}"
- name: "WARREN_API_DB_NAME"
value: "{{ .Values.fastapi.db.name }}"
- name: "WARREN_API_DB_USER"
value: "{{ .Values.fastapi.db.user }}"
- name: "WARREN_API_DB_PASSWORD"
valueFrom:
secretKeyRef:
name: warren-api-secrets
key: WARREN_API_DB_PASSWORD
- name: "WARREN_API_DB_ENGINE"
value: "{{ .Values.fastapi.db.engine }}"
- name: "WARREN_API_DB_HOST"
value: "{{ .Values.fastapi.db.host }}"
- name: "WARREN_API_DB_PORT"
value: "{{ .Values.fastapi.db.port }}"
- name: "WARREN_ALLOWED_HOSTS"
value: {{ printf "%q" .Values.fastapi.allowedHosts | replace " " "," | quote }}
- name: "WARREN_LRS_HOSTS"
value: "{{ .Values.fastapi.lrs.hosts }}"
- name: "WARREN_LRS_AUTH_BASIC_USERNAME"
value: "{{ .Values.fastapi.lrs.username }}"
- name: "WARREN_LRS_AUTH_BASIC_PASSWORD"
valueFrom:
secretKeyRef:
name: warren-api-secrets
key: WARREN_LRS_AUTH_BASIC_PASSWORD
- name: "WARREN_APP_SIGNING_ALGORITHM"
value: "{{ .Values.fastapi.signingAlgorithm }}"
- name: "WARREN_APP_SIGNING_KEY"
valueFrom:
secretKeyRef:
name: warren-api-secrets
key: WARREN_APP_SIGNING_KEY
{{- range $key, $val := .Values.env.secret }}
- name: {{ $val.envName }}
valueFrom:
secretKeyRef:
name: {{ $val.secretName }}
key: {{ $val.keyName }}
{{- end }}
{{- end }}

{{/*
ImagePullSecrets
*/}}
{{- define "fastapi.imagePullSecrets" -}}
{{- $pullSecrets := .Values.imagePullSecrets }}
{{- if (not (empty $pullSecrets)) }}
imagePullSecrets:
{{- range $pullSecrets }}
- name: {{ . }}
{{ end }}
{{- end -}}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Values.loggingConfigConfigMap }}"
name: "{{ template "api.fullname" . }}-logging-config"
labels:
{{- include "api.labels" . | nindent 4 }}
data:
Expand Down
71 changes: 24 additions & 47 deletions src/helm/warren/charts/api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "api.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "api.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "api.selectorLabels" . | nindent 6 }}
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -19,72 +20,48 @@ spec:
{{- end }}
labels:
{{- include "api.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- include "fastapi.imagePullSecrets" . | nindent 6 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
- name: "{{ .Chart.Name }}-fastapi"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
livenessProbe:
httpGet:
path: /__heartbeat__
port: http
httpHeaders:
- name: Host
value: '{{ first .Values.allowedHosts | trimPrefix "https://" }}'
initialDelaySeconds: 15
periodSeconds: 30
readinessProbe:
httpGet:
path: /__lbheartbeat__
port: http
httpHeaders:
- name: Host
value: '{{ first .Values.allowedHosts | trimPrefix "https://" }}'
initialDelaySeconds: 5
periodSeconds: 5
startupProbe:
exec:
command:
- "bash"
- "-c"
- "warren migration check"
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 120
env:
- name: WARREN_API_SERVER_PORT
value: "{{ .Values.service.port }}"
- name: WARREN_API_DB_ENGINE
value: {{ .Values.database.engine }}
- name: WARREN_API_DB_PORT
value: {{ .Values.database.port | quote }}
- name: WARREN_APP_SIGNING_ALGORITHM
value: {{ .Values.signingAlgorithm }}
- name: WARREN_ALLOWED_HOSTS
value: {{ include "api.allowedHosts" . }}
envFrom:
- secretRef:
name: {{ .Values.envVarsSecret | quote }}
{{ with .Values.podCommand }}
{{- include "api.envs" . | nindent 12 }}
{{ with .Values.fastapi.command }}
command:
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
- name: logging-config
mountPath: "/etc/warren/api"
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: logging-config
configMap:
name: "warren-api-logging-config"
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
Loading

0 comments on commit 3957581

Please sign in to comment.