Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 1 | {{/* |
| 2 | # Copyright © 2018 Amdocs, AT&T, Bell Canada |
| 3 | # Copyright © 2020 Samsung Electronics |
Bruno Sakoto | 1ed3d26 | 2021-03-05 18:11:00 -0500 | [diff] [blame] | 4 | # Modifications Copyright (C) 2021 Bell Canada. |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 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 }} |
milaszki | bdcb416 | 2020-07-07 11:28:15 +0000 | [diff] [blame] | 22 | apiVersion: apps/v1 |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 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: |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 34 | replicas: 1 |
milaszki | bdcb416 | 2020-07-07 11:28:15 +0000 | [diff] [blame] | 35 | selector: |
| 36 | matchLabels: |
| 37 | app: {{ include "common.name" $dot }}-{{ $pgMode }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 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: |
andreas-geissler | f84cccd | 2021-07-07 15:40:41 +0200 | [diff] [blame^] | 45 | imagePullSecrets: |
| 46 | - name: "{{ include "common.namespace" $dot }}-docker-registry-key" |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 47 | initContainers: |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 48 | - command: |
| 49 | - sh |
| 50 | args: |
| 51 | - -c |
Krzysztof Opasiak | b0a2d3b | 2020-05-25 15:38:48 +0200 | [diff] [blame] | 52 | - | |
| 53 | function prepare_password { |
| 54 | echo -n $1 | sed -e "s/'/''/g" |
| 55 | } |
| 56 | export PG_PRIMARY_PASSWORD=`prepare_password $PG_PRIMARY_PASSWORD_INPUT`; |
| 57 | export PG_PASSWORD=`prepare_password $PG_PASSWORD_INPUT`; |
| 58 | export PG_ROOT_PASSWORD=`prepare_password $PG_ROOT_PASSWORD_INPUT`; |
| 59 | cd /config-input && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/config/${PFILE}; done |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 60 | env: |
| 61 | - name: PG_PRIMARY_USER |
| 62 | value: primaryuser |
Tomasz Pietruszkiewicz | e24ed0b | 2021-03-18 11:14:06 +0100 | [diff] [blame] | 63 | - name: MODE |
| 64 | value: postgres |
Krzysztof Opasiak | b0a2d3b | 2020-05-25 15:38:48 +0200 | [diff] [blame] | 65 | - name: PG_PRIMARY_PASSWORD_INPUT |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 66 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 67 | - name: PG_USER |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 68 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }} |
Krzysztof Opasiak | b0a2d3b | 2020-05-25 15:38:48 +0200 | [diff] [blame] | 69 | - name: PG_PASSWORD_INPUT |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 70 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 71 | - name: PG_DATABASE |
| 72 | value: "{{ $dot.Values.config.pgDatabase }}" |
Krzysztof Opasiak | b0a2d3b | 2020-05-25 15:38:48 +0200 | [diff] [blame] | 73 | - name: PG_ROOT_PASSWORD_INPUT |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 74 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 75 | volumeMounts: |
| 76 | - mountPath: /config-input/setup.sql |
| 77 | name: config |
| 78 | subPath: setup.sql |
| 79 | - mountPath: /config |
| 80 | name: pgconf |
Sylvain Desbureaux | 6a1ae6c | 2020-11-19 17:23:14 +0100 | [diff] [blame] | 81 | image: {{ include "repositoryGenerator.image.envsubst" $dot }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 82 | imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }} |
| 83 | name: {{ include "common.name" $dot }}-update-config |
| 84 | |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 85 | - name: init-sysctl |
| 86 | command: |
| 87 | - /bin/sh |
| 88 | - -c |
| 89 | - | |
| 90 | chown 26:26 /podroot/; |
| 91 | chmod 700 /podroot/; |
Sylvain Desbureaux | 6a1ae6c | 2020-11-19 17:23:14 +0100 | [diff] [blame] | 92 | image: {{ include "repositoryGenerator.image.busybox" $dot }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 93 | imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }} |
| 94 | volumeMounts: |
| 95 | - name: {{ include "common.fullname" $dot }}-data |
| 96 | mountPath: /podroot/ |
| 97 | containers: |
| 98 | - name: {{ include "common.name" $dot }} |
Sylvain Desbureaux | 6a1ae6c | 2020-11-19 17:23:14 +0100 | [diff] [blame] | 99 | image: {{ include "repositoryGenerator.image.postgres" $dot }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 100 | imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }} |
| 101 | ports: |
| 102 | - containerPort: {{ $dot.Values.service.internalPort }} |
| 103 | name: {{ $dot.Values.service.portName }} |
| 104 | # disable liveness probe when breakpoints set in debugger |
| 105 | # so K8s doesn't restart unresponsive container |
| 106 | {{- if eq $dot.Values.liveness.enabled true }} |
| 107 | livenessProbe: |
| 108 | tcpSocket: |
| 109 | port: {{ $dot.Values.service.internalPort }} |
| 110 | initialDelaySeconds: {{ $dot.Values.liveness.initialDelaySeconds }} |
| 111 | periodSeconds: {{ $dot.Values.liveness.periodSeconds }} |
| 112 | timeoutSeconds: {{ $dot.Values.liveness.timeoutSeconds }} |
| 113 | {{- end }} |
| 114 | readinessProbe: |
| 115 | tcpSocket: |
| 116 | port: {{ $dot.Values.service.internalPort }} |
| 117 | initialDelaySeconds: {{ $dot.Values.readiness.initialDelaySeconds }} |
| 118 | periodSeconds: {{ $dot.Values.readiness.periodSeconds }} |
| 119 | env: |
| 120 | - name: PGHOST |
| 121 | value: /tmp |
| 122 | - name: PG_PRIMARY_USER |
| 123 | value: primaryuser |
Tomasz Pietruszkiewicz | e24ed0b | 2021-03-18 11:14:06 +0100 | [diff] [blame] | 124 | - name: MODE |
| 125 | value: postgres |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 126 | - name: PG_MODE |
| 127 | value: {{ $pgMode }} |
| 128 | - name: PG_PRIMARY_HOST |
| 129 | value: "{{ $dot.Values.container.name.primary }}" |
| 130 | - name: PG_REPLICA_HOST |
| 131 | value: "{{ $dot.Values.container.name.replica }}" |
| 132 | - name: PG_PRIMARY_PORT |
| 133 | value: "{{ $dot.Values.service.internalPort }}" |
| 134 | - name: PG_PRIMARY_PASSWORD |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 135 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.primaryPasswordUID" .) "key" "password") | indent 10 }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 136 | - name: PG_USER |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 137 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "login") | indent 10 }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 138 | - name: PG_PASSWORD |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 139 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.userCredentialsUID" .) "key" "password") | indent 10 }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 140 | - name: PG_DATABASE |
| 141 | value: "{{ $dot.Values.config.pgDatabase }}" |
| 142 | - name: PG_ROOT_PASSWORD |
Krzysztof Opasiak | c0a57f8 | 2020-03-23 15:50:13 +0100 | [diff] [blame] | 143 | {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" (include "common.postgres.secret.rootPassUID" .) "key" "password") | indent 10 }} |
Bruno Sakoto | 1ed3d26 | 2021-03-05 18:11:00 -0500 | [diff] [blame] | 144 | - name: PGDATA_PATH_OVERRIDE |
| 145 | value: "{{ $dot.Values.config.pgDataPath }}" |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 146 | volumeMounts: |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 147 | - name: config |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 148 | mountPath: /pgconf/pool_hba.conf |
| 149 | subPath: pool_hba.conf |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 150 | - name: pgconf |
| 151 | mountPath: /pgconf/setup.sql |
| 152 | subPath: setup.sql |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 153 | - mountPath: /pgdata |
| 154 | name: {{ include "common.fullname" $dot }}-data |
| 155 | - mountPath: /backup |
| 156 | name: {{ include "common.fullname" $dot }}-backup |
| 157 | readOnly: true |
Sylvain Desbureaux | 335781f | 2020-09-23 10:31:50 +0200 | [diff] [blame] | 158 | resources: {{ include "common.resources" $dot | nindent 12 }} |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 159 | {{- if $dot.Values.nodeSelector }} |
| 160 | nodeSelector: |
| 161 | {{ toYaml $dot.Values.nodeSelector | indent 10 }} |
| 162 | {{- end -}} |
| 163 | {{- if $dot.Values.affinity }} |
| 164 | affinity: |
| 165 | {{ toYaml $dot.Values.affinity | indent 10 }} |
| 166 | {{- end }} |
| 167 | volumes: |
| 168 | - name: localtime |
| 169 | hostPath: |
| 170 | path: /etc/localtime |
| 171 | - name: {{ include "common.fullname" $dot }}-backup |
| 172 | emptyDir: {} |
| 173 | - name: {{ include "common.fullname" $dot }}-data |
| 174 | {{- if $dot.Values.persistence.enabled }} |
| 175 | persistentVolumeClaim: |
| 176 | claimName: {{ include "common.fullname" $dot }}-{{ $pgMode }} |
| 177 | {{- else }} |
| 178 | emptyDir: {} |
| 179 | {{ end }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 180 | - name: config |
Krzysztof Opasiak | 56ca885 | 2020-02-04 16:07:20 +0100 | [diff] [blame] | 181 | configMap: |
| 182 | name: {{ include "common.fullname" $dot }} |
Krzysztof Opasiak | 1754734 | 2020-03-10 23:53:31 +0100 | [diff] [blame] | 183 | - name: pgconf |
| 184 | emptyDir: |
| 185 | medium: Memory |
| 186 | {{- end -}} |