blob: 3777c1b2e40e1b46efbe84bedb5a67c8c9dc3843 [file] [log] [blame]
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +01001{{/*
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 }}
21apiVersion: apps/v1beta1
22kind: Deployment
23metadata:
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 }}"
32spec:
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 - name: init-sysctl
44 command:
45 - /bin/sh
46 - -c
47 - |
48 chown 26:26 /podroot/;
49 chmod 700 /podroot/;
50 image: {{ $dot.Values.global.busyboxRepository | default $dot.Values.busyboxRepository }}/{{ $dot.Values.busyboxImage }}
51 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
52 volumeMounts:
53 - name: {{ include "common.fullname" $dot }}-data
54 mountPath: /podroot/
55 containers:
56 - name: {{ include "common.name" $dot }}
57 image: "{{ $dot.Values.postgresRepository }}/{{ $dot.Values.image }}"
58 imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
59 ports:
60 - containerPort: {{ $dot.Values.service.internalPort }}
61 name: {{ $dot.Values.service.portName }}
62 # disable liveness probe when breakpoints set in debugger
63 # so K8s doesn't restart unresponsive container
64 {{- if eq $dot.Values.liveness.enabled true }}
65 livenessProbe:
66 tcpSocket:
67 port: {{ $dot.Values.service.internalPort }}
68 initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }}
69 periodSeconds: {{ $dot.Values.liveness.periodSeconds }}
70 timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }}
71 {{- end }}
72 readinessProbe:
73 tcpSocket:
74 port: {{ $dot.Values.service.internalPort }}
75 initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }}
76 periodSeconds: {{ $dot.Values.readiness.periodSeconds }}
77 env:
78 - name: PGHOST
79 value: /tmp
80 - name: PG_PRIMARY_USER
81 value: primaryuser
82 - name: PG_MODE
83 value: {{ $pgMode }}
84 - name: PG_PRIMARY_HOST
85 value: "{{ $dot.Values.container.name.primary }}"
86 - name: PG_REPLICA_HOST
87 value: "{{ $dot.Values.container.name.replica }}"
88 - name: PG_PRIMARY_PORT
89 value: "{{ $dot.Values.service.internalPort }}"
90 - name: PG_PRIMARY_PASSWORD
Krzysztof Opasiakf1f945b2020-02-04 21:16:50 +010091 {{- include "common.secret.envFromSecret" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010092 - name: PG_USER
Krzysztof Opasiakf1f945b2020-02-04 21:16:50 +010093 {{- include "common.secret.envFromSecret" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010094 - name: PG_PASSWORD
Krzysztof Opasiakf1f945b2020-02-04 21:16:50 +010095 {{- include "common.secret.envFromSecret" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +010096 - name: PG_DATABASE
97 value: "{{ $dot.Values.config.pgDatabase }}"
98 - name: PG_ROOT_PASSWORD
Krzysztof Opasiakf1f945b2020-02-04 21:16:50 +010099 {{- include "common.secret.envFromSecret" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }}
Krzysztof Opasiak56ca8852020-02-04 16:07:20 +0100100 volumeMounts:
101 - name: pool-hba-conf
102 mountPath: /pgconf/pool_hba.conf
103 subPath: pool_hba.conf
104 - mountPath: /pgdata
105 name: {{ include "common.fullname" $dot }}-data
106 - mountPath: /backup
107 name: {{ include "common.fullname" $dot }}-backup
108 readOnly: true
109 resources:
110{{ include "common.resources" $dot | indent 12 }}
111 {{- if $dot.Values.nodeSelector }}
112 nodeSelector:
113{{ toYaml $dot.Values.nodeSelector | indent 10 }}
114 {{- end -}}
115 {{- if $dot.Values.affinity }}
116 affinity:
117{{ toYaml $dot.Values.affinity | indent 10 }}
118 {{- end }}
119 volumes:
120 - name: localtime
121 hostPath:
122 path: /etc/localtime
123 - name: {{ include "common.fullname" $dot }}-backup
124 emptyDir: {}
125 - name: {{ include "common.fullname" $dot }}-data
126{{- if $dot.Values.persistence.enabled }}
127 persistentVolumeClaim:
128 claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }}
129{{- else }}
130 emptyDir: {}
131{{ end }}
132 - name: pool-hba-conf
133 configMap:
134 name: {{ include "common.fullname" $dot }}
135{{- end -}}