Skip to content

Commit

Permalink
feat(initContainer): Tune start-up process (#10454)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik authored Jul 25, 2024
1 parent 2714b3b commit c38c0c1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
49 changes: 48 additions & 1 deletion helm/defectdojo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,51 @@ Create chart name and version as used by the chart label.
{{- else -}}
{{ .Values.django.mediaPersistentVolume.persistentVolumeClaim.name }}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Define db-migration-checker
*/}}
{{- define "dbMigrationChecker" -}}
- name: db-migration-checker
command:
- sh
- -c
# - tail -f /dev/null
- while ! /app/manage.py migrate --check; do echo "Database is not migrated to the latest state yet"; sleep 5; done;
image: '{{ template "django.uwsgi.repository" . }}:{{ .Values.tag }}'
imagePullPolicy: {{ .Values.imagePullPolicy }}
{{- if .Values.securityContext.enabled }}
securityContext:
{{- toYaml .Values.securityContext.djangoSecurityContext | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .fullName }}
- secretRef:
name: {{ .fullName }}-extrasecrets
optional: true
env:
{{- if .Values.django.uwsgi.enable_debug }}
- name: DD_DEBUG
value: 'True'
{{- end }}
- name: DD_DATABASE_PASSWORD
valueFrom:
secretKeyRef:
{{- if eq .Values.database "postgresql" }}
name: {{ .Values.postgresql.auth.existingSecret | default "defectdojo-postgresql-specific" }}
key: {{ .Values.postgresql.auth.secretKeys.userPasswordKey | default "postgresql-password" }}
{{- else if eq .Values.database "postgresqlha" }}
name: {{ .Values.postgresqlha.postgresql.existingSecret | default "defectdojo-postgresql-ha-specific" }}
key: postgresql-postgres-password
{{- else if eq .Values.database "mysql" }}
name: {{ .Values.mysql.auth.existingSecret | default "defectdojo-mysql-specific" }}
key: {{ .Values.mysql.auth.secretKey | default "mysql-password" }}
{{- end }}
{{- if .Values.extraEnv }}
{{- toYaml .Values.extraEnv | nindent 8 }}
{{- end }}
resources:
{{- toYaml .Values.django.uwsgi.resources | nindent 10 }}
{{- end -}}
6 changes: 6 additions & 0 deletions helm/defectdojo/templates/celery-beat-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ spec:
path: {{ .hostPath }}
{{- end }}
{{- end }}
{{- if .Values.dbMigrationChecker.enabled }}
initContainers:
{{$data := dict "fullName" $fullName }}
{{- $newContext := merge . (dict "fullName" $fullName) }}
{{- include "dbMigrationChecker" $newContext | nindent 6 }}
{{- end }}
containers:
{{- if .Values.cloudsql.enabled }}
- name: cloudsql-proxy
Expand Down
6 changes: 6 additions & 0 deletions helm/defectdojo/templates/celery-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ spec:
path: {{ .hostPath }}
{{- end }}
{{- end }}
{{- if .Values.dbMigrationChecker.enabled }}
initContainers:
{{$data := dict "fullName" $fullName }}
{{- $newContext := merge . (dict "fullName" $fullName) }}
{{- include "dbMigrationChecker" $newContext | nindent 6 }}
{{- end }}
containers:
{{- if .Values.cloudsql.enabled }}
- name: cloudsql-proxy
Expand Down
6 changes: 6 additions & 0 deletions helm/defectdojo/templates/django-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ spec:
emptyDir: {}
{{- end }}
{{- end }}
{{- if .Values.dbMigrationChecker.enabled }}
initContainers:
{{$data := dict "fullName" $fullName }}
{{- $newContext := merge . (dict "fullName" $fullName) }}
{{- include "dbMigrationChecker" $newContext | nindent 6 }}
{{- end }}
containers:
{{- if .Values.cloudsql.enabled }}
- name: cloudsql-proxy
Expand Down
5 changes: 4 additions & 1 deletion helm/defectdojo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ securityContext:
# nginx dockerfile sets USER=1001
runAsUser: 1001

dbMigrationChecker:
enabled: true

tests:
unitTests:
resources:
Expand Down Expand Up @@ -219,7 +222,7 @@ django:
# Enable liveness checks on uwsgi container. Those values are use on nginx readiness checks as well.
enabled: true
failureThreshold: 6
initialDelaySeconds: 120
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
Expand Down

0 comments on commit c38c0c1

Please sign in to comment.