blob: 341b4c86c7eb86d144f71ccca48b3058014aa9e4 [file] [log] [blame]
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +01001{{/*
2# Copyright © 2018 Amdocs, AT&T, Bell Canada
3# Copyright © 2020 Samsung Electronics
Abdelmuhaimen Seaudi988aeed2021-09-23 21:11:44 +00004# Copyright © 2021 Orange
Bruno Sakoto1ed3d262021-03-05 18:11:00 -05005# Modifications Copyright (C) 2021 Bell Canada.
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +01006# #
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
10# #
11# # http://www.apache.org/licenses/LICENSE-2.0
12# #
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.
18*/}}
19
20{{- define "common.postgres.deployment" -}}
21 {{- $dot := .dot }}
22 {{- $pgMode := .pgMode }}
milaszkibdcb4162020-07-07 11:28:15 +000023apiVersion: apps/v1
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010024kind: Deployment
25metadata:
26 name: {{ include "common.fullname" $dot }}-{{ $pgMode }}
27 namespace: {{ include "common.namespace" $dot }}
28 labels:
29 app: {{ include "common.name" $dot }}-{{ $pgMode }}
30 chart: {{ $dot.Chart.Name }}-{{ $dot.Chart.Version | replace "+" "_" }}
31 release: {{ include "common.release" $dot }}
32 heritage: {{ $dot.Release.Service }}
33 name: "{{ index $dot.Values "container" "name" $pgMode }}"
34spec:
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010035 replicas: 1
milaszkibdcb4162020-07-07 11:28:15 +000036 selector:
37 matchLabels:
38 app: {{ include "common.name" $dot }}-{{ $pgMode }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010039 template:
40 metadata:
41 labels:
42 app: {{ include "common.name" $dot }}-{{ $pgMode }}
43 release: {{ include "common.release" $dot }}
44 name: "{{ index $dot.Values "container" "name" $pgMode }}"
45 spec:
andreas-geisslerf84cccd2021-07-07 15:40:41 +020046 imagePullSecrets:
47 - name: "{{ include "common.namespace" $dot }}-docker-registry-key"
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010048 initContainers:
Krzysztof Opasiak17547342020-03-10 23:53:31 +010049 - command:
50 - sh
51 args:
52 - -c
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020053 - |
54 function prepare_password {
55 echo -n $1 | sed -e "s/'/''/g"
56 }
57 export PG_PRIMARY_PASSWORD=`prepare_password $PG_PRIMARY_PASSWORD_INPUT`;
58 export PG_PASSWORD=`prepare_password $PG_PASSWORD_INPUT`;
59 export PG_ROOT_PASSWORD=`prepare_password $PG_ROOT_PASSWORD_INPUT`;
60 cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done
Krzysztof Opasiak17547342020-03-10 23:53:31 +010061 env:
62 - name: PG_PRIMARY_USER
63 value: primaryuser
Tomasz Pietruszkiewicze24ed0b2021-03-18 11:14:06 +010064 - name: MODE
65 value: postgres
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020066 - name: PG_PRIMARY_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010067 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010068 - name: PG_USER
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010069 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020070 - name: PG_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010071 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010072 - name: PG_DATABASE
73 value: "{{ $dot.Values.config.pgDatabase }}"
Krzysztof Opasiakb0a2d3b2020-05-25 15:38:48 +020074 - name: PG_ROOT_PASSWORD_INPUT
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +010075 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010076 volumeMounts:
77 - mountPath: /config-input/setup.sql
78 name: config
79 subPath: setup.sql
80 - mountPath: /config
81 name: pgconf
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +010082 image: {{ include "repositoryGenerator.image.envsubst" $dot }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +010083 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
84 name: {{ include "common.name" $dot }}-update-config
85
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010086 - name: init-sysctl
87 command:
88 - /bin/sh
89 - -c
90 - |
91 chown 26:26 /podroot/;
92 chmod 700 /podroot/;
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +010093 image: {{ include "repositoryGenerator.image.busybox" $dot }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010094 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
95 volumeMounts:
96 - name: {{ include "common.fullname" $dot }}-data
97 mountPath: /podroot/
98 containers:
99 - name: {{ include "common.name" $dot }}
Sylvain Desbureaux6a1ae6c2020-11-19 17:23:14 +0100100 image: {{ include "repositoryGenerator.image.postgres" $dot }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100101 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
102 ports:
103 - containerPort: {{ $dot.Values.service.internalPort }}
104 name: {{ $dot.Values.service.portName }}
105 # disable liveness probe when breakpoints set in debugger
106 # so K8s doesn't restart unresponsive container
107 {{- if eq $dot.Values.liveness.enabled true }}
108 livenessProbe:
109 tcpSocket:
110 port: {{ $dot.Values.service.internalPort }}
111 initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
112 periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
113 timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
114 {{- end }}
115 readinessProbe:
116 tcpSocket:
117 port: {{ $dot.Values.service.internalPort }}
118 initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
119 periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
120 env:
121 - name: PGHOST
122 value: /tmp
123 - name: PG_PRIMARY_USER
124 value: primaryuser
Tomasz Pietruszkiewicze24ed0b2021-03-18 11:14:06 +0100125 - name: MODE
126 value: postgres
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100127 - name: PG_MODE
128 value: {{ $pgMode }}
129 - name: PG_PRIMARY_HOST
Abdelmuhaimen Seaudi988aeed2021-09-23 21:11:44 +0000130 value: "{{ $dot.Values.service.name2 }}"
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100131 - name: PG_REPLICA_HOST
Abdelmuhaimen Seaudi988aeed2021-09-23 21:11:44 +0000132 value: "{{ $dot.Values.service.name3 }}"
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100133 - name: PG_PRIMARY_PORT
134 value: "{{ $dot.Values.service.internalPort }}"
135 - name: PG_PRIMARY_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100136 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100137 - name: PG_USER
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100138 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100139 - name: PG_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100140 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100141 - name: PG_DATABASE
142 value: "{{ $dot.Values.config.pgDatabase }}"
143 - name: PG_ROOT_PASSWORD
Krzysztof Opasiakc0a57f82020-03-23 15:50:13 +0100144 {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
Bruno Sakoto1ed3d262021-03-05 18:11:00 -0500145 - name: PGDATA_PATH_OVERRIDE
146 value: "{{ $dot.Values.config.pgDataPath }}"
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100147 volumeMounts:
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100148 - name: config
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100149 mountPath: /pgconf/pool_hba.conf
150 subPath: pool_hba.conf
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100151 - name: pgconf
152 mountPath: /pgconf/setup.sql
153 subPath: setup.sql
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100154 - mountPath: /pgdata
155 name: {{ include "common.fullname" $dot }}-data
156 - mountPath: /backup
157 name: {{ include "common.fullname" $dot }}-backup
158 readOnly: true
Sylvain Desbureaux335781f2020-09-23 10:31:50 +0200159 resources: {{ include "common.resources" $dot | nindent 12 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100160 {{- if $dot.Values.nodeSelector }}
161 nodeSelector:
162{{ toYaml $dot.Values.nodeSelector | indent 10 }}
163 {{- end -}}
164 {{- if $dot.Values.affinity }}
165 affinity:
166{{ toYaml $dot.Values.affinity | indent 10 }}
167 {{- end }}
168 volumes:
169 - name: localtime
170 hostPath:
171 path: /etc/localtime
172 - name: {{ include "common.fullname" $dot }}-backup
173 emptyDir: {}
174 - name: {{ include "common.fullname" $dot }}-data
175{{- if $dot.Values.persistence.enabled }}
176 persistentVolumeClaim:
177 claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
178{{- else }}
179 emptyDir: {}
180{{ end }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100181 - name: config
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100182 configMap:
183 name: {{ include "common.fullname" $dot }}
Krzysztof Opasiak17547342020-03-10 23:53:31 +0100184 - name: pgconf
185 emptyDir:
186 medium: Memory
187{{- end -}}