Add standalone R3 RIC platform helm charts and deployment scripts.
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / charts / postgresql / templates / statefulset.yaml
1 apiVersion: apps/v1
2 kind: StatefulSet
3 metadata:
4   name: {{ template "postgresql.master.fullname" . }}
5   labels:
6     app: {{ template "postgresql.name" . }}
7     chart: {{ template "postgresql.chart" . }}
8     release: {{ .Release.Name | quote }}
9     heritage: {{ .Release.Service | quote }}
10 spec:
11   serviceName: {{ template "postgresql.fullname" . }}-headless
12   replicas: 1
13   updateStrategy:
14     type: {{ .Values.updateStrategy.type }}
15   selector:
16     matchLabels:
17       app: {{ template "postgresql.name" . }}
18       release: {{ .Release.Name | quote }}
19       role: master
20   template:
21     metadata:
22       name: {{ template "postgresql.fullname" . }}
23       labels:
24         app: {{ template "postgresql.name" . }}
25         chart: {{ template "postgresql.chart" . }}
26         release: {{ .Release.Name | quote }}
27         heritage: {{ .Release.Service | quote }}
28         role: master
29     spec:
30       {{- if .Values.securityContext.enabled }}
31       securityContext:
32         fsGroup: {{ .Values.securityContext.fsGroup }}
33         runAsUser: {{ .Values.securityContext.runAsUser }}
34       {{- end }}
35       {{- if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets }}
36       imagePullSecrets:
37       {{- range .Values.image.pullSecrets }}
38         - name: {{ . }}
39       {{- end}}
40       {{- range .Values.metrics.image.pullSecrets }}
41         - name: {{ . }}
42       {{- end}}
43       {{- end }}
44       {{- if .Values.master.nodeSelector }}
45       nodeSelector:
46 {{ toYaml .Values.master.nodeSelector | indent 8 }}
47       {{- end }}
48       {{- if .Values.master.affinity }}
49       affinity:
50 {{ toYaml .Values.master.affinity | indent 8 }}
51       {{- end }}
52       {{- if .Values.master.tolerations }}
53       tolerations:
54 {{ toYaml .Values.master.tolerations | indent 8 }}
55       {{- end }}
56       {{- if .Values.terminationGracePeriodSeconds }}
57       terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
58       {{- end }}
59       {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
60       initContainers:
61       - name: init-chmod-data
62         image: {{ template "postgresql.volumePermissions.image" . }}
63         imagePullPolicy: "{{ .Values.volumePermissions.image.pullPolicy }}"
64         resources:
65 {{ toYaml .Values.resources | indent 10 }}
66         command:
67           - sh
68           - -c
69           - |
70             chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} /bitnami
71             if [ -d /bitnami/postgresql/data ]; then
72               chmod  0700 /bitnami/postgresql/data;
73             fi
74         securityContext:
75           runAsUser: {{ .Values.volumePermissions.securityContext.runAsUser }}
76         volumeMounts:
77         - name: data
78           mountPath: /bitnami/postgresql
79       {{- end }}
80       containers:
81       - name: {{ template "postgresql.fullname" . }}
82         image: {{ template "postgresql.image" . }}
83         imagePullPolicy: "{{ .Values.image.pullPolicy }}"
84         resources:
85 {{ toYaml .Values.resources | indent 10 }}
86         env:
87         {{- if .Values.image.debug}}
88         - name: BASH_DEBUG
89           value: "1"
90         - name: NAMI_DEBUG
91           value: "1"
92         {{- end }}
93         {{- if .Values.replication.enabled }}
94         - name: POSTGRESQL_REPLICATION_MODE
95           value: "master"
96         - name: POSTGRESQL_REPLICATION_USER
97           value: {{ .Values.replication.user | quote }}
98         {{- if .Values.usePasswordFile }}
99         - name: POSTGRESQL_REPLICATION_PASSWORD_FILE
100           value: "/opt/bitnami/postgresql/secrets/postgresql-replication-password"
101         {{- else }}
102         - name: POSTGRESQL_REPLICATION_PASSWORD
103           valueFrom:
104             secretKeyRef:
105               name: {{ template "postgresql.secretName" . }}
106               key: postgresql-replication-password
107         {{- end }}
108         {{- if not (eq .Values.replication.synchronousCommit "off")}}
109         - name: POSTGRESQL_SYNCHRONOUS_COMMIT_MODE
110           value: {{ .Values.replication.synchronousCommit | quote }}
111         - name: POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS
112           value: {{ .Values.replication.numSynchronousReplicas | quote }}
113         {{- end }}
114         - name: POSTGRESQL_CLUSTER_APP_NAME
115           value: {{ .Values.replication.applicationName }}
116         {{- end }}
117         - name: POSTGRESQL_USERNAME
118           value: {{ .Values.postgresqlUsername | quote }}
119         {{- if .Values.usePasswordFile }}
120         - name: POSTGRESQL_PASSWORD_FILE
121           value: "/opt/bitnami/postgresql/secrets/postgresql-password"
122         {{- else }}
123         - name: POSTGRESQL_PASSWORD
124           valueFrom:
125             secretKeyRef:
126               name: {{ template "postgresql.secretName" . }}
127               key: postgresql-password
128         {{- end }}
129         {{- if .Values.postgresqlDatabase }}
130         - name: POSTGRESQL_DATABASE
131           value: {{ .Values.postgresqlDatabase | quote }}
132         {{- end }}
133 {{- if .Values.extraEnv }}
134 {{ toYaml .Values.extraEnv | indent 8 }}
135 {{- end }}
136         ports:
137         - name: postgresql
138           containerPort: {{ .Values.service.port }}
139         {{- if .Values.livenessProbe.enabled }}
140         livenessProbe:
141           exec:
142             command:
143             - sh
144             - -c
145            {{- if .Values.postgresqlDatabase }}
146             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -d {{ .Values.postgresqlDatabase | quote }} -h localhost
147            {{- else }}
148             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -h localhost
149            {{- end }}
150           initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
151           periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
152           timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
153           successThreshold: {{ .Values.livenessProbe.successThreshold }}
154           failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
155         {{- end }}
156         {{- if .Values.readinessProbe.enabled }}
157         readinessProbe:
158           exec:
159             command:
160             - sh
161             - -c
162            {{- if .Values.postgresqlDatabase }}
163             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -d {{ .Values.postgresqlDatabase | quote }} -h localhost
164            {{- else }}
165             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -h localhost
166            {{- end }}
167           initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
168           periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
169           timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
170           successThreshold: {{ .Values.readinessProbe.successThreshold }}
171           failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
172         {{- end }}
173         volumeMounts:
174         {{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.initdbScriptsConfigMap .Values.initdbScripts }}
175         - name: custom-init-scripts
176           mountPath: /docker-entrypoint-initdb.d
177         {{- end }}
178         {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.postgresqlExtendedConf .Values.extendedConfConfigMap }}
179         - name: postgresql-extended-config
180           mountPath: /bitnami/postgresql/conf/conf.d/
181         {{- end }}
182         {{- if .Values.usePasswordFile }}
183         - name: postgresql-password
184           mountPath: /opt/bitnami/postgresql/secrets/
185         {{- end }}
186         {{- if .Values.persistence.enabled }}
187         - name: data
188           mountPath: {{ .Values.persistence.mountPath }}
189         {{- end }}
190         {{- if or (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresqlConfiguration .Values.pgHbaConfiguration .Values.configurationConfigMap }}
191         - name: postgresql-config
192           mountPath: /bitnami/postgresql/conf
193         {{- end }}
194 {{- if .Values.metrics.enabled }}
195       - name: metrics
196         image: {{ template "metrics.image" . }}
197         imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
198         env:
199         {{- $database := required "In order to enable metrics you need to specify a database (.Values.postgresqlDatabase)" .Values.postgresqlDatabase }}
200         - name: DATA_SOURCE_URI
201           value: {{ printf "localhost:%d/%s?sslmode=disable" (int .Values.service.port) $database | quote }}
202         {{- if .Values.usePasswordFile }}
203         - name: DATA_SOURCE_PASS_FILE
204           value: "/opt/bitnami/postgresql/secrets/postgresql-password"
205         {{- else }}
206         - name: DATA_SOURCE_PASS
207           valueFrom:
208             secretKeyRef:
209               name: {{ template "postgresql.secretName" . }}
210               key: postgresql-password
211         {{- end }}
212         - name: DATA_SOURCE_USER
213           value: {{ .Values.postgresqlUsername }}
214         {{- if .Values.livenessProbe.enabled }}
215         livenessProbe:
216           httpGet:
217             path: /
218             port: metrics
219           initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }}
220           periodSeconds: {{ .Values.metrics.livenessProbe.periodSeconds }}
221           timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }}
222           successThreshold: {{ .Values.metrics.livenessProbe.successThreshold }}
223           failureThreshold: {{ .Values.metrics.livenessProbe.failureThreshold }}
224         {{- end }}
225         {{- if .Values.readinessProbe.enabled }}
226         readinessProbe:
227           httpGet:
228             path: /
229             port: metrics
230           initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }}
231           periodSeconds: {{ .Values.metrics.readinessProbe.periodSeconds }}
232           timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }}
233           successThreshold: {{ .Values.metrics.readinessProbe.successThreshold }}
234           failureThreshold: {{ .Values.metrics.readinessProbe.failureThreshold }}
235         {{- end }}
236         volumeMounts:
237         {{- if .Values.usePasswordFile }}
238         - name: postgresql-password
239           mountPath: /opt/bitnami/postgresql/secrets/
240         {{- end }}
241         ports:
242         - name: metrics
243           containerPort: 9187
244         resources:
245 {{ toYaml .Values.metrics.resources | indent 10 }}
246 {{- end }}
247       volumes:
248       {{- if or (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresqlConfiguration .Values.pgHbaConfiguration .Values.configurationConfigMap}}
249       - name: postgresql-config
250         configMap:
251           name: {{ template "postgresql.configurationCM" . }}
252       {{- end }}
253       {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.postgresqlExtendedConf .Values.extendedConfConfigMap }}
254       - name: postgresql-extended-config
255         configMap:
256           name: {{ template "postgresql.extendedConfigurationCM" . }}
257       {{- end }}
258       {{- if .Values.usePasswordFile }}
259       - name: postgresql-password
260         secret:
261           secretName: {{ template "postgresql.secretName" . }}
262       {{- end }}
263       {{- if  or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.initdbScriptsConfigMap .Values.initdbScripts }}
264       - name: custom-init-scripts
265         configMap:
266           name: {{ template "postgresql.initdbScriptsCM" . }}
267       {{- end }}
268 {{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
269       - name: data
270         persistentVolumeClaim:
271           claimName: {{ .Values.persistence.existingClaim }}
272 {{- else if not .Values.persistence.enabled }}
273       - name: data
274         emptyDir: {}
275 {{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
276   volumeClaimTemplates:
277     - metadata:
278         name: data
279       {{- with .Values.persistence.annotations }}
280         annotations:
281         {{- range $key, $value := . }}
282           {{ $key }}: {{ $value }}
283         {{- end }}
284       {{- end }}
285       spec:
286         accessModes:
287         {{- range .Values.persistence.accessModes }}
288           - {{ . | quote }}
289         {{- end }}
290         resources:
291           requests:
292             storage: {{ .Values.persistence.size | quote }}
293       {{- if .Values.persistence.storageClass }}
294       {{- if (eq "-" .Values.persistence.storageClass) }}
295         storageClassName: ""
296       {{- else }}
297         storageClassName: "{{ .Values.persistence.storageClass }}"
298       {{- end }}
299       {{- end }}
300 {{- end }}