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