e3ac66933fdeea421b8150c0e294073ba5089e00
[oom.git] / kubernetes / common / postgres / templates / _deployment.tpl
1 {{/*
2 # Copyright © 2018 Amdocs, AT&T, Bell Canada
3 # Copyright © 2020 Samsung Electronics
4 # #
5 # # Licensed under the Apache License, Version 2.0 (the "License");
6 # # you may not use this file except in compliance with the License.
7 # # You may obtain a copy of the License at
8 # #
9 # #       http://www.apache.org/licenses/LICENSE-2.0
10 # #
11 # # Unless required by applicable law or agreed to in writing, software
12 # # distributed under the License is distributed on an "AS IS" BASIS,
13 # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # # See the License for the specific language governing permissions and
15 # # limitations under the License.
16 */}}
17
18 {{- define "common.postgres.deployment" -}}
19   {{- $dot := .dot }}
20   {{- $pgMode := .pgMode }}
21 apiVersion: apps/v1beta1
22 kind: Deployment
23 metadata:
24   name: {{ include "common.fullname" $dot }}-{{ $pgMode }}
25   namespace: {{ include "common.namespace" $dot }}
26   labels:
27     app: {{ include "common.name" $dot }}-{{ $pgMode }}
28     chart: {{ $dot.Chart.Name }}-{{ $dot.Chart.Version | replace "+" "_" }}
29     release: {{ include "common.release" $dot }}
30     heritage: {{ $dot.Release.Service }}
31     name: "{{ index $dot.Values "container" "name" $pgMode }}"
32 spec:
33   serviceName: {{ $dot.Values.service.name }}
34   replicas: 1
35   template:
36     metadata:
37       labels:
38         app: {{ include "common.name" $dot }}-{{ $pgMode }}
39         release: {{ include "common.release" $dot }}
40         name: "{{ index $dot.Values "container" "name" $pgMode }}"
41     spec:
42       initContainers:
43       - command:
44         - sh
45         args:
46         - -c
47         - "cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done"
48         env:
49         - name: PG_PRIMARY_USER
50           value: primaryuser
51         - name: PG_PRIMARY_PASSWORD
52           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
53         - name: PG_USER
54           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
55         - name: PG_PASSWORD
56           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
57         - name: PG_DATABASE
58           value: "{{ $dot.Values.config.pgDatabase }}"
59         - name: PG_ROOT_PASSWORD
60           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
61         volumeMounts:
62         - mountPath: /config-input/setup.sql
63           name: config
64           subPath: setup.sql
65         - mountPath: /config
66           name: pgconf
67         image: "{{ $dot.Values.global.envsubstImage }}"
68         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
69         name: {{ include "common.name" $dot }}-update-config
70
71       - name: init-sysctl
72         command:
73         - /bin/sh
74         - -c
75         - |
76           chown 26:26 /podroot/;
77           chmod 700 /podroot/;
78         image: {{ $dot.Values.global.busyboxRepository | default $dot.Values.busyboxRepository }}/{{ $dot.Values.busyboxImage }}
79         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
80         volumeMounts:
81         - name: {{ include "common.fullname" $dot }}-data
82           mountPath: /podroot/
83       containers:
84       - name: {{ include "common.name" $dot }}
85         image: "{{ $dot.Values.postgresRepository }}/{{ $dot.Values.image }}"
86         imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
87         ports:
88         - containerPort: {{ $dot.Values.service.internalPort }}
89           name: {{ $dot.Values.service.portName }}
90         # disable liveness probe when breakpoints set in debugger
91         # so K8s doesn't restart unresponsive container
92         {{- if eq $dot.Values.liveness.enabled true }}
93         livenessProbe:
94           tcpSocket:
95             port: {{ $dot.Values.service.internalPort }}
96           initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
97           periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
98           timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
99         {{- end }}
100         readinessProbe:
101           tcpSocket:
102             port: {{ $dot.Values.service.internalPort }}
103           initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
104           periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
105         env:
106         - name: PGHOST
107           value: /tmp
108         - name: PG_PRIMARY_USER
109           value: primaryuser
110         - name: PG_MODE
111           value: {{ $pgMode }}
112         - name: PG_PRIMARY_HOST
113           value: "{{ $dot.Values.container.name.primary }}"
114         - name: PG_REPLICA_HOST
115           value: "{{ $dot.Values.container.name.replica }}"
116         - name: PG_PRIMARY_PORT
117           value: "{{ $dot.Values.service.internalPort }}"
118         - name: PG_PRIMARY_PASSWORD
119           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
120         - name: PG_USER
121           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
122         - name: PG_PASSWORD
123           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
124         - name: PG_DATABASE
125           value: "{{ $dot.Values.config.pgDatabase }}"
126         - name: PG_ROOT_PASSWORD
127           {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
128         volumeMounts:
129         - name: config
130           mountPath: /pgconf/pool_hba.conf
131           subPath: pool_hba.conf
132         - name: pgconf
133           mountPath: /pgconf/setup.sql
134           subPath: setup.sql
135         - mountPath: /pgdata
136           name: {{ include "common.fullname" $dot }}-data
137         - mountPath: /backup
138           name: {{ include "common.fullname" $dot }}-backup
139           readOnly: true
140         resources:
141 {{ include "common.resources" $dot | indent 12 }}
142         {{- if $dot.Values.nodeSelector }}
143         nodeSelector:
144 {{ toYaml $dot.Values.nodeSelector | indent 10 }}
145         {{- end -}}
146         {{- if $dot.Values.affinity }}
147         affinity:
148 {{ toYaml $dot.Values.affinity | indent 10 }}
149         {{- end }}
150       volumes:
151       - name: localtime
152         hostPath:
153           path: /etc/localtime
154       - name: {{ include "common.fullname" $dot }}-backup
155         emptyDir: {}
156       - name: {{ include "common.fullname" $dot }}-data
157 {{- if $dot.Values.persistence.enabled }}
158         persistentVolumeClaim:
159             claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
160 {{- else }}
161         emptyDir: {}
162 {{ end }}
163       - name: config
164         configMap:
165           name: {{ include "common.fullname" $dot }}
166       - name: pgconf
167         emptyDir:
168           medium: Memory
169 {{- end -}}