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