2 # Copyright © 2018 Amdocs, AT&T, Bell Canada
3 # Copyright © 2020 Samsung Electronics
4 # Copyright © 2021 Orange
5 # Modifications Copyright (C) 2021 Bell Canada.
7 # # Licensed under the Apache License, Version 2.0 (the "License");
8 # # you may not use this file except in compliance with the License.
9 # # You may obtain a copy of the License at
11 # # http://www.apache.org/licenses/LICENSE-2.0
13 # # Unless required by applicable law or agreed to in writing, software
14 # # distributed under the License is distributed on an "AS IS" BASIS,
15 # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # # See the License for the specific language governing permissions and
17 # # limitations under the License.
20 {{- define "common.postgres.deployment" -}}
22 {{- $pgMode := .pgMode }}
26 name: {{ include "common.fullname" $dot }}-{{ $pgMode }}
27 namespace: {{ include "common.namespace" $dot }}
29 app: {{ include "common.name" $dot }}-{{ $pgMode }}
30 app.kubernetes.io/name: {{ include "common.name" $dot }}-{{ $pgMode }}
31 {{- if $dot.Chart.AppVersion }}
32 version: "{{ $dot.Chart.AppVersion | replace "+" "_" }}"
34 version: "{{ $dot.Chart.Version | replace "+" "_" }}"
36 chart: {{ $dot.Chart.Name }}-{{ $dot.Chart.Version | replace "+" "_" }}
37 release: {{ include "common.release" $dot }}
38 heritage: {{ $dot.Release.Service }}
39 name: "{{ index $dot.Values "container" "name" $pgMode }}"
46 app: {{ include "common.name" $dot }}-{{ $pgMode }}
50 app: {{ include "common.name" $dot }}-{{ $pgMode }}
51 app.kubernetes.io/name: {{ include "common.name" $dot }}-{{ $pgMode }}
52 {{- if $dot.Chart.AppVersion }}
53 version: "{{ $dot.Chart.AppVersion | replace "+" "_" }}"
55 version: "{{ $dot.Chart.Version | replace "+" "_" }}"
57 release: {{ include "common.release" $dot }}
58 name: "{{ index $dot.Values "container" "name" $pgMode }}"
61 - name: "{{ include "common.namespace" $dot }}-docker-registry-key"
68 function prepare_password {
69 echo -n $1 | sed -e "s/'/''/g"
71 export PG_PRIMARY_PASSWORD=`prepare_password $PG_PRIMARY_PASSWORD_INPUT`;
72 export PG_PASSWORD=`prepare_password $PG_PASSWORD_INPUT`;
73 export PG_ROOT_PASSWORD=`prepare_password $PG_ROOT_PASSWORD_INPUT`;
74 cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done
76 - name: PG_PRIMARY_USER
80 - name: PG_PRIMARY_PASSWORD_INPUT
81 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
83 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
84 - name: PG_PASSWORD_INPUT
85 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
87 value: "{{ $dot.Values.config.pgDatabase }}"
88 - name: PG_ROOT_PASSWORD_INPUT
89 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
91 - mountPath: /config-input/setup.sql
96 image: {{ include "repositoryGenerator.image.envsubst" $dot }}
97 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
98 name: {{ include "common.name" $dot }}-update-config
105 chown 26:26 /podroot/;
107 image: {{ include "repositoryGenerator.image.busybox" $dot }}
108 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
110 - name: {{ include "common.fullname" $dot }}-data
113 - name: {{ include "common.name" $dot }}
114 image: {{ include "repositoryGenerator.image.postgres" $dot }}
115 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
117 - containerPort: {{ $dot.Values.service.internalPort }}
118 name: {{ $dot.Values.service.portName }}
119 # disable liveness probe when breakpoints set in debugger
120 # so K8s doesn't restart unresponsive container
121 {{- if eq $dot.Values.liveness.enabled true }}
124 port: {{ $dot.Values.service.internalPort }}
125 initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
126 periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
127 timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
131 port: {{ $dot.Values.service.internalPort }}
132 initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
133 periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
137 - name: PG_PRIMARY_USER
143 - name: PG_PRIMARY_HOST
144 value: "{{ $dot.Values.service.name2 }}"
145 - name: PG_REPLICA_HOST
146 value: "{{ $dot.Values.service.name3 }}"
147 - name: PG_PRIMARY_PORT
148 value: "{{ $dot.Values.service.internalPort }}"
149 - name: PG_PRIMARY_PASSWORD
150 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
152 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
154 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
156 value: "{{ $dot.Values.config.pgDatabase }}"
157 - name: PG_ROOT_PASSWORD
158 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
159 - name: PGDATA_PATH_OVERRIDE
160 value: "{{ $dot.Values.config.pgDataPath }}"
163 mountPath: /pgconf/pool_hba.conf
164 subPath: pool_hba.conf
166 mountPath: /pgconf/setup.sql
169 name: {{ include "common.fullname" $dot }}-data
171 name: {{ include "common.fullname" $dot }}-backup
173 resources: {{ include "common.resources" $dot | nindent 10 }}
174 {{- if (default false $dot.Values.metrics.enabled) }}
175 - name: {{ include "common.name" $dot }}-metrics
176 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ $dot.Values.metrics.image }}
177 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.metrics.pullPolicy | quote}}
179 - name: POSTGRES_METRICS_EXTRA_FLAGS
180 value: {{ default "" (join " " $dot.Values.metrics.extraFlags) | quote }}
181 - name: DATA_SOURCE_USER
182 value: "{{ $dot.Values.metrics.postgresUser }}"
183 - name: DATA_SOURCE_PASS
184 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 12 }}
189 DATA_SOURCE_URI="127.0.0.1:5432/?sslmode=disable" ./bin/postgres_exporter $POSTGRES_METRICS_EXTRA_FLAGS
191 {{- range $index, $metricPort := $dot.Values.metrics.ports }}
192 - name: {{ $metricPort.name }}
193 containerPort: {{ $metricPort.port }}
200 initialDelaySeconds: {{ $dot.Values.metrics.livenessProbe.initialDelaySeconds }}
201 periodSeconds: {{ $dot.Values.metrics.livenessProbe.periodSeconds }}
202 timeoutSeconds: {{ $dot.Values.metrics.livenessProbe.timeoutSeconds }}
203 successThreshold: {{ $dot.Values.metrics.livenessProbe.successThreshold }}
204 failureThreshold: {{ $dot.Values.metrics.livenessProbe.failureThreshold }}
209 initialDelaySeconds: {{ $dot.Values.metrics.readinessProbe.initialDelaySeconds }}
210 periodSeconds: {{ $dot.Values.metrics.readinessProbe.periodSeconds }}
211 timeoutSeconds: {{ $dot.Values.metrics.readinessProbe.timeoutSeconds }}
212 successThreshold: {{ $dot.Values.metrics.readinessProbe.successThreshold }}
213 failureThreshold: {{ $dot.Values.metrics.readinessProbe.failureThreshold }}
214 {{ include "common.containerSecurityContext" $dot | indent 10 | trim }}
215 resources: {{- toYaml $dot.Values.metrics.resources | nindent 12 }}
217 {{- if $dot.Values.nodeSelector }}
219 {{ toYaml $dot.Values.nodeSelector | indent 10 }}
221 {{- if $dot.Values.affinity }}
223 {{ toYaml $dot.Values.affinity | indent 10 }}
229 - name: {{ include "common.fullname" $dot }}-backup
231 - name: {{ include "common.fullname" $dot }}-data
232 {{- if $dot.Values.persistence.enabled }}
233 persistentVolumeClaim:
234 claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
240 name: {{ include "common.fullname" $dot }}