Skip to content

Commit

Permalink
add init containers to wait for mongo to avoid crashes; enable migrat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
dejanzele committed Jul 16, 2024
1 parent cbfd735 commit 70c35c0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
21 changes: 21 additions & 0 deletions charts/testkube-cloud-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ spec:
serviceAccountName: {{ include "testkube-cloud-api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: wait-for-mongo
image: alpine/mongosh:2.0.2
command: ["/bin/sh", "-c"]
args:
- |
until mongosh "$API_MONGO_DSN" --eval "print('MongoDB is ready')" > /dev/null 2>&1; do
echo "Waiting for MongoDB ($API_MONGO_DSN) to become ready..."
sleep 5
done
echo "MongoDB is ready"
env:
- name: API_MONGO_DSN
{{- if (or .Values.global.mongo.dsnSecretRef .Values.api.mongo.dsnSecretRef) }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.global.mongo.dsnSecretRef | default .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.global.mongo.dsn | default .Values.api.mongo.dsn }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
21 changes: 21 additions & 0 deletions charts/testkube-cloud-api/templates/migrations-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ spec:
serviceAccountName: {{ include "testkube-cloud-api.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: wait-for-mongo
image: alpine/mongosh:2.0.2
command: ["/bin/sh", "-c"]
args:
- |
until mongosh "$API_MONGO_DSN" --eval "print('MongoDB is ready')" > /dev/null 2>&1; do
echo "Waiting for MongoDB ($API_MONGO_DSN) to become ready..."
sleep 5
done
echo "MongoDB is ready"
env:
- name: API_MONGO_DSN
{{- if (or .Values.global.mongo.dsnSecretRef .Values.api.mongo.dsnSecretRef) }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.global.mongo.dsnSecretRef | default .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.global.mongo.dsn | default .Values.api.mongo.dsn }}
{{- end }}
containers:
- name: migrations
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
2 changes: 1 addition & 1 deletion charts/testkube-enterprise/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ testkube-cloud-api:
tlsSecret: testkube-enterprise-api-tls
migrations:
# -- Toggle whether to run database migrations
enabled: false
enabled: true
# -- Toggle whether to enable pre-install & pre-upgrade hooks (should be disabled if mongo is installed using this chart)
useHelmHooks: false
image:
Expand Down
21 changes: 21 additions & 0 deletions charts/testkube-worker-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ spec:
serviceAccountName: {{ include "testkube-worker-service.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
- name: wait-for-mongo
image: alpine/mongosh:2.0.2
command: ["/bin/sh", "-c"]
args:
- |
until mongosh "$API_MONGO_DSN" --eval "print('MongoDB is ready')" > /dev/null 2>&1; do
echo "Waiting for MongoDB ($API_MONGO_DSN) to become ready..."
sleep 5
done
echo "MongoDB is ready"
env:
- name: API_MONGO_DSN
{{- if (or .Values.global.mongo.dsnSecretRef .Values.api.mongo.dsnSecretRef) }}
valueFrom:
secretKeyRef:
key: MONGO_DSN
name: {{ .Values.global.mongo.dsnSecretRef | default .Values.api.mongo.dsnSecretRef }}
{{- else }}
value: {{ .Values.global.mongo.dsn | default .Values.api.mongo.dsn }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down

0 comments on commit 70c35c0

Please sign in to comment.