Merge "[AAI] Update certs to be valid until Jan 2022"
[oom.git] / kubernetes / common / postgres / templates / _deployment.tpl
1 {{/*
2 # Copyright © 2018 Amdocs, AT&T, Bell Canada
3 # Copyright © 2020 Samsung Electronics
4 # Modifications Copyright (C) 2021 Bell Canada.
5 # #
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 }}
22 apiVersion: apps/v1
23 kind: Deployment
24 metadata:
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 }}"
33 spec:
34   replicas: 1
35   selector:
36     matchLabels:
37       app: {{ include "common.name" $dot }}-{{ $pgMode }}
38   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:
46       - command:
47         - sh
48         args:
49         - -c
50         - |
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
58         env:
59         - name: PG_PRIMARY_USER
60           value: primaryuser
61         - name: PG_PRIMARY_PASSWORD_INPUT
62           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
63         - name: PG_USER
64           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
65         - name: PG_PASSWORD_INPUT
66           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
67         - name: PG_DATABASE
68           value: "{{ $dot.Values.config.pgDatabase }}"
69         - name: PG_ROOT_PASSWORD_INPUT
70           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
71         volumeMounts:
72         - mountPath: /config-input/setup.sql
73           name: config
74           subPath: setup.sql
75         - mountPath: /config
76           name: pgconf
77         image: {{ include "repositoryGenerator.image.envsubst" $dot }}
78         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
79         name: {{ include "common.name" $dot }}-update-config
80
81       - name: init-sysctl
82         command:
83         - /bin/sh
84         - -c
85         - |
86           chown 26:26 /podroot/;
87           chmod 700 /podroot/;
88         image: {{ include "repositoryGenerator.image.busybox" $dot }}
89         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
90         volumeMounts:
91         - name: {{ include "common.fullname" $dot }}-data
92           mountPath: /podroot/
93       containers:
94       - name: {{ include "common.name" $dot }}
95         image: {{ include "repositoryGenerator.image.postgres" $dot }}
96         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
97         ports:
98         - containerPort: {{ $dot.Values.service.internalPort }}
99           name: {{ $dot.Values.service.portName }}
100         # disable liveness probe when breakpoints set in debugger
101         # so K8s doesn't restart unresponsive container
102         {{- if eq $dot.Values.liveness.enabled true }}
103         livenessProbe:
104           tcpSocket:
105             port: {{ $dot.Values.service.internalPort }}
106           initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
107           periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
108           timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
109         {{- end }}
110         readinessProbe:
111           tcpSocket:
112             port: {{ $dot.Values.service.internalPort }}
113           initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
114           periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
115         env:
116         - name: PGHOST
117           value: /tmp
118         - name: PG_PRIMARY_USER
119           value: primaryuser
120         - name: PG_MODE
121           value: {{ $pgMode }}
122         - name: PG_PRIMARY_HOST
123           value: "{{ $dot.Values.container.name.primary }}"
124         - name: PG_REPLICA_HOST
125           value: "{{ $dot.Values.container.name.replica }}"
126         - name: PG_PRIMARY_PORT
127           value: "{{ $dot.Values.service.internalPort }}"
128         - name: PG_PRIMARY_PASSWORD
129           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
130         - name: PG_USER
131           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
132         - name: PG_PASSWORD
133           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
134         - name: PG_DATABASE
135           value: "{{ $dot.Values.config.pgDatabase }}"
136         - name: PG_ROOT_PASSWORD
137           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
138         - name: PGDATA_PATH_OVERRIDE
139           value: "{{ $dot.Values.config.pgDataPath }}"
140         volumeMounts:
141         - name: config
142           mountPath: /pgconf/pool_hba.conf
143           subPath: pool_hba.conf
144         - name: pgconf
145           mountPath: /pgconf/setup.sql
146           subPath: setup.sql
147         - mountPath: /pgdata
148           name: {{ include "common.fullname" $dot }}-data
149         - mountPath: /backup
150           name: {{ include "common.fullname" $dot }}-backup
151           readOnly: true
152         resources: {{ include "common.resources" $dot | nindent 12 }}
153         {{- if $dot.Values.nodeSelector }}
154         nodeSelector:
155 {{ toYaml $dot.Values.nodeSelector | indent 10 }}
156         {{- end -}}
157         {{- if $dot.Values.affinity }}
158         affinity:
159 {{ toYaml $dot.Values.affinity | indent 10 }}
160         {{- end }}
161       volumes:
162       - name: localtime
163         hostPath:
164           path: /etc/localtime
165       - name: {{ include "common.fullname" $dot }}-backup
166         emptyDir: {}
167       - name: {{ include "common.fullname" $dot }}-data
168 {{- if $dot.Values.persistence.enabled }}
169         persistentVolumeClaim:
170             claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
171 {{- else }}
172         emptyDir: {}
173 {{ end }}
174       - name: config
175         configMap:
176           name: {{ include "common.fullname" $dot }}
177       - name: pgconf
178         emptyDir:
179           medium: Memory
180 {{- end -}}