J release changes
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / templates / migrations.yaml
1 {{- if .Values.deployment.kong.enabled }}
2 {{- if .Release.IsInstall -}}
3 {{/* .migrations.init isn't normally exposed in values.yaml, since it should
4      generally always run on install--there should never be any reason to
5      disable it, and at worst it's a no-op. However, https://github.com/helm/helm/issues/3308
6      means we cannot use the default function to create a hidden value, hence
7      the workaround with this $runInit variable.
8  */}}
9 {{- $runInit := true -}}
10 {{- if (hasKey .Values.migrations "init") -}}
11   {{- $runInit = .Values.migrations.init -}}
12 {{- end -}}
13
14 {{- if (and ($runInit) (not (eq .Values.env.database "off"))) }}
15 apiVersion: batch/v1
16 kind: Job
17 metadata:
18   name: {{ template "kong.fullname" . }}-init-migrations
19   namespace: {{ template "kong.namespace" . }}
20   labels:
21     {{- include "kong.metaLabels" . | nindent 4 }}
22     app.kubernetes.io/component: init-migrations
23   annotations:
24     argocd.argoproj.io/hook: Sync
25     argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
26   {{- range $key, $value := .Values.migrations.jobAnnotations }}
27     {{ $key }}: {{ $value | quote }}
28   {{- end }}
29 spec:
30   backoffLimit: {{ .Values.migrations.backoffLimit }}
31   template:
32     metadata:
33       name: {{ template "kong.name" . }}-init-migrations
34       labels:
35         {{- include "kong.metaLabels" . | nindent 8 }}
36         app.kubernetes.io/component: init-migrations
37       {{- if .Values.migrations.annotations }}
38       annotations:
39       {{- range $key, $value := .Values.migrations.annotations }}
40         {{ $key }}: {{ $value | quote }}
41       {{- end }}
42       {{- if (and (not .Values.deployment.serviceAccount.automountServiceAccountToken) (or .Values.deployment.serviceAccount.create .Values.deployment.serviceAccount.name)) }}
43         kuma.io/service-account-token-volume: {{ template "kong.serviceAccountTokenName" . }}
44       {{- end }}
45       {{- end }}
46     spec:
47       {{- if or .Values.deployment.serviceAccount.create .Values.deployment.serviceAccount.name }}
48       serviceAccountName: {{ template "kong.serviceAccountName" . }}
49       {{- end }}
50       {{- if (and (or .Values.deployment.serviceAccount.create .Values.deployment.serviceAccount.name) .Values.deployment.serviceAccount.automountServiceAccountToken) }}
51       automountServiceAccountToken: true
52       {{- else }}
53       automountServiceAccountToken: false
54       {{ end }}
55       {{- if .Values.image.pullSecrets }}
56       imagePullSecrets:
57       {{- range .Values.image.pullSecrets }}
58         - name: {{ . }}
59       {{- end }}
60       {{- end }}
61       {{- if (or (and (.Values.postgresql.enabled) .Values.waitImage.enabled) .Values.deployment.initContainers) }}
62       initContainers:
63       {{- if .Values.deployment.initContainers }}
64       {{- toYaml .Values.deployment.initContainers | nindent 6 }}
65       {{- end }}
66       {{- if (and (.Values.postgresql.enabled) .Values.waitImage.enabled) }}
67       {{- include "kong.wait-for-postgres" . | nindent 6 }}
68       {{- end }}
69       {{- end }}
70       containers:
71       {{- if .Values.migrations.sidecarContainers }}
72       {{- toYaml .Values.migrations.sidecarContainers | nindent 6 }}
73       {{- end }}
74       - name: {{ template "kong.name" . }}-migrations
75         image: {{ include "kong.getRepoTag" .Values.image }}
76         imagePullPolicy: {{ .Values.image.pullPolicy }}
77         securityContext:
78         {{ toYaml .Values.containerSecurityContext | nindent 10 }} 
79         env:
80         {{- include "kong.no_daemon_env" . | nindent 8 }}
81         {{- include "kong.envFrom" .Values.envFrom | nindent 8 }}
82         args: [ "kong", "migrations", "bootstrap" ]
83         volumeMounts:
84         {{- include "kong.volumeMounts" . | nindent 8 }}
85         {{- include "kong.userDefinedVolumeMounts" .Values.deployment | nindent 8 }}
86         resources:
87         {{- toYaml .Values.migrations.resources | nindent 10 }}
88       securityContext:
89       {{- include "kong.podsecuritycontext" . | nindent 8 }}
90       {{- if .Values.affinity }}
91       affinity:
92       {{- toYaml .Values.affinity | nindent 8 }}
93       {{- end }}
94       {{- if .Values.nodeSelector }}
95       nodeSelector:
96       {{- toYaml .Values.nodeSelector | nindent 8 }}
97       {{- end }}
98       {{- if .Values.tolerations }}
99       tolerations:
100       {{- toYaml .Values.tolerations | nindent 8 }}
101       {{- end }}
102       restartPolicy: OnFailure
103       volumes:
104       {{- include "kong.volumes" . | nindent 6 -}}
105       {{- include "kong.userDefinedVolumes" . | nindent 6 -}}
106 {{- end }}
107 {{- end }}
108 {{- end }}