blob: 7d04501f24a828d7804ba7cb48e0c2ee66fcf507 [file] [log] [blame]
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +01001{{/*
2# Copyright © 2018 Amdocs, AT&T, Bell Canada
3# Copyright © 2020 Samsung Electronics
Bruno Sakoto1ed3d262021-03-05 18:11:00 -05004# Modifications Copyright (C) 2021 Bell Canada.
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +01005# #
6# # Licensed under the Apache License, Version 2.0 (the "License");
7# # you may not use this file except in compliance with the License.
8# # You may obtain a copy of the License at
9# #
10# # http://www.apache.org/licenses/LICENSE-2.0
11# #
12# # Unless required by applicable law or agreed to in writing, software
13# # distributed under the License is distributed on an "AS IS" BASIS,
14# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# # See the License for the specific language governing permissions and
16# # limitations under the License.
17*/}}
18
19{{- define "common.postgres.deployment" -}}
20 {{- $dot := .dot }}
21 {{- $pgMode := .pgMode }}
milaszkibdcb4162020-07-07 11:28:15 +000022apiVersion: apps/v1
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010023kind: Deployment
24metadata:
25 name: {{ include "common.fullname" $dot }}-{{ $pgMode }}
26 namespace: {{ include "common.namespace" $dot }}
27 labels:
28 app: {{ include "common.name" $dot }}-{{ $pgMode }}
29 chart: {{ $dot.Chart.Name }}-{{ $dot.Chart.Version | replace "+" "_" }}
30 release: {{ include "common.release" $dot }}
31 heritage: {{ $dot.Release.Service }}
32 name: "{{ index $dot.Values "container" "name" $pgMode }}"
33spec:
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010034 replicas: 1
milaszkibdcb4162020-07-07 11:28:15 +000035 selector:
36 matchLabels:
37 app: {{ include "common.name" $dot }}-{{ $pgMode }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010038 template:
39 metadata:
40 labels:
41 app: {{ include "common.name" $dot }}-{{ $pgMode }}
42 release: {{ include "common.release" $dot }}
43 name: "{{ index $dot.Values "container" "name" $pgMode }}"
44 spec:
45 initContainers:
Krzysztof Opasiak17547342020-03-10 23:53:31 +010046 - command:
47 - sh
48 args:
49 - -c
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020050 - |
51 function prepare_password {
52 echo -n $1 | sed -e "s/'/''/g"
53 }
54 export PG_PRIMARY_PASSWORD=`prepare_password $PG_PRIMARY_PASSWORD_INPUT`;
55 export PG_PASSWORD=`prepare_password $PG_PASSWORD_INPUT`;
56 export PG_ROOT_PASSWORD=`prepare_password $PG_ROOT_PASSWORD_INPUT`;
57 cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done
Krzysztof Opasiak17547342020-03-10 23:53:31 +010058 env:
59 - name: PG_PRIMARY_USER
60 value: primaryuser
Tomasz Pietruszkiewicze24ed0b2021-03-18 11:14:06 +010061 - name: MODE
62 value: postgres
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020063 - name: PG_PRIMARY_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010064 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010065 - name: PG_USER
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010066 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020067 - name: PG_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010068 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010069 - name: PG_DATABASE
70 value: "{{ $dot.Values.config.pgDatabase }}"
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020071 - name: PG_ROOT_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010072 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010073 volumeMounts:
74 - mountPath: /config-input/setup.sql
75 name: config
76 subPath: setup.sql
77 - mountPath: /config
78 name: pgconf
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +010079 image: {{ include "repositoryGenerator.image.envsubst" $dot }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010080 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
81 name: {{ include "common.name" $dot }}-update-config
82
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010083 - name: init-sysctl
84 command:
85 - /bin/sh
86 - -c
87 - |
88 chown 26:26 /podroot/;
89 chmod 700 /podroot/;
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +010090 image: {{ include "repositoryGenerator.image.busybox" $dot }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010091 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
92 volumeMounts:
93 - name: {{ include "common.fullname" $dot }}-data
94 mountPath: /podroot/
95 containers:
96 - name: {{ include "common.name" $dot }}
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +010097 image: {{ include "repositoryGenerator.image.postgres" $dot }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010098 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
99 ports:
100 - containerPort: {{ $dot.Values.service.internalPort }}
101 name: {{ $dot.Values.service.portName }}
102 # disable liveness probe when breakpoints set in debugger
103 # so K8s doesn't restart unresponsive container
104 {{- if eq $dot.Values.liveness.enabled true }}
105 livenessProbe:
106 tcpSocket:
107 port: {{ $dot.Values.service.internalPort }}
108 initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
109 periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
110 timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
111 {{- end }}
112 readinessProbe:
113 tcpSocket:
114 port: {{ $dot.Values.service.internalPort }}
115 initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
116 periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
117 env:
118 - name: PGHOST
119 value: /tmp
120 - name: PG_PRIMARY_USER
121 value: primaryuser
Tomasz Pietruszkiewicze24ed0b2021-03-18 11:14:06 +0100122 - name: MODE
123 value: postgres
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100124 - name: PG_MODE
125 value: {{ $pgMode }}
126 - name: PG_PRIMARY_HOST
127 value: "{{ $dot.Values.container.name.primary }}"
128 - name: PG_REPLICA_HOST
129 value: "{{ $dot.Values.container.name.replica }}"
130 - name: PG_PRIMARY_PORT
131 value: "{{ $dot.Values.service.internalPort }}"
132 - name: PG_PRIMARY_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100133 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100134 - name: PG_USER
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100135 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100136 - name: PG_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100137 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100138 - name: PG_DATABASE
139 value: "{{ $dot.Values.config.pgDatabase }}"
140 - name: PG_ROOT_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100141 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
Bruno Sakoto1ed3d262021-03-05 18:11:00 -0500142 - name: PGDATA_PATH_OVERRIDE
143 value: "{{ $dot.Values.config.pgDataPath }}"
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100144 volumeMounts:
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100145 - name: config
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100146 mountPath: /pgconf/pool_hba.conf
147 subPath: pool_hba.conf
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100148 - name: pgconf
149 mountPath: /pgconf/setup.sql
150 subPath: setup.sql
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100151 - mountPath: /pgdata
152 name: {{ include "common.fullname" $dot }}-data
153 - mountPath: /backup
154 name: {{ include "common.fullname" $dot }}-backup
155 readOnly: true
Sylvain Desbureaux335781f2020-09-23 10:31:50 +0200156 resources: {{ include "common.resources" $dot | nindent 12 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100157 {{- if $dot.Values.nodeSelector }}
158 nodeSelector:
159{{ toYaml $dot.Values.nodeSelector | indent 10 }}
160 {{- end -}}
161 {{- if $dot.Values.affinity }}
162 affinity:
163{{ toYaml $dot.Values.affinity | indent 10 }}
164 {{- end }}
165 volumes:
166 - name: localtime
167 hostPath:
168 path: /etc/localtime
169 - name: {{ include "common.fullname" $dot }}-backup
170 emptyDir: {}
171 - name: {{ include "common.fullname" $dot }}-data
172{{- if $dot.Values.persistence.enabled }}
173 persistentVolumeClaim:
174 claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
175{{- else }}
176 emptyDir: {}
177{{ end }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100178 - name: config
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100179 configMap:
180 name: {{ include "common.fullname" $dot }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100181 - name: pgconf
182 emptyDir:
183 medium: Memory
184{{- end -}}