# helm_charts_migrations.yaml
{{- if (and (.Values.runMigrations) (not (eq .Values.env.database "off"))) }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "kong.fullname" . }}-init-migrations
  labels:
    {{- include "kong.metaLabels" . | nindent 4 }}
    app.kubernetes.io/component: init-migrations
spec:
  template:
    metadata:
      name: {{ template "kong.name" . }}-init-migrations
      labels:
        {{- include "kong.metaLabels" . | nindent 8 }}
        app.kubernetes.io/component: init-migrations
    spec:
      {{- if .Values.podSecurityPolicy.enabled }}
      serviceAccountName: {{ template "kong.serviceAccountName" . }}
      {{- end }}
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range .Values.image.pullSecrets }}
        - name: {{ . }}
      {{- end }}
      {{- end }}
      initContainers:
      {{- if (eq .Values.env.database "postgres") }}
      {{- include "kong.wait-for-postgres" . | nindent 6 }}
      {{- end }}
      containers:
      - name: {{ template "kong.name" . }}-migrations
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
        {{- include "kong.final_env" . | nindent 8 }}
        command: [ "/bin/sh", "-c", "kong migrations bootstrap" ]
        volumeMounts:
        {{- include "kong.volumeMounts" . | nindent 8 }}
      securityContext:
      {{- include "kong.podsecuritycontext" . | nindent 8 }}
      restartPolicy: OnFailure
      volumes:
      {{- include "kong.volumes" . | nindent 6 -}}
{{- end }}