{{- if .Values.migrations.enabled }} apiVersion: batch/v1 kind: Job metadata: name: {{ include "monitoring-platform.fullname" . }}-migrations labels: {{- include "monitoring-platform.labels" . | nindent 4 }} app.kubernetes.io/component: migrations annotations: # Runs AFTER the release manifests are applied (post-install/post-upgrade), # so new pods may briefly run against the old schema until this job # finishes; application code must tolerate that window. We cannot use a # pre-install hook: on first install the chart's own PostgreSQL would not # exist yet for the migrations to run against. "helm.sh/hook": post-install,post-upgrade "helm.sh/hook-weight": "-5" "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded spec: backoffLimit: 3 template: metadata: labels: {{- include "monitoring-platform.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: migrations spec: restartPolicy: OnFailure {{- if .Values.serviceAccount.create }} serviceAccountName: {{ include "monitoring-platform.serviceAccountName" . }} {{- end }} {{- if .Values.postgresql.enabled }} initContainers: # Wait for embedded PostgreSQL to be ready - name: wait-for-postgresql image: busybox:1.36 command: - /bin/sh - -c - | echo "Waiting for PostgreSQL to be ready..." until nc -z {{ include "monitoring-platform.fullname" . }}-postgresql 5432; do echo "PostgreSQL is not ready yet, waiting..." sleep 2 done echo "PostgreSQL is ready!" {{- end }} containers: - name: migrations {{- if .Values.migrations.image.repository }} image: "{{ .Values.migrations.image.repository }}:{{ .Values.migrations.image.tag | default (.Values.image.tag | default .Chart.AppVersion) }}" {{- else }} image: "{{ .Values.image.repository }}-migrations:{{ .Values.image.tag | default .Chart.AppVersion }}" {{- end }} imagePullPolicy: {{ .Values.global.imagePullPolicy }} env: {{- include "monitoring-platform.secretEnv" (dict "ctx" . "name" "POSTGRES_URL" "key" "postgres_url" "secret" .Values.postgresql.existingSecret "secretKey" .Values.postgresql.existingSecretKey) | nindent 12 }} {{- with .Values.extraEnv }} {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.migrations.extraEnv }} {{- toYaml . | nindent 12 }} {{- end }} resources: {{- toYaml .Values.migrations.resources | nindent 12 }} {{- with .Values.image.pullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} {{- end }}