Merge "[SDNC] Use common secret template in dmaap-listener"
[oom.git] / kubernetes / common / postgres-legacy / templates / statefulset.yaml
1 {{/*
2 # Copyright © 2018 Amdocs, AT&T, Bell Canada
3 # #
4 # # Licensed under the Apache License, Version 2.0 (the "License");
5 # # you may not use this file except in compliance with the License.
6 # # You may obtain a copy of the License at
7 # #
8 # #       http://www.apache.org/licenses/LICENSE-2.0
9 # #
10 # # Unless required by applicable law or agreed to in writing, software
11 # # distributed under the License is distributed on an "AS IS" BASIS,
12 # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # # See the License for the specific language governing permissions and
14 # # limitations under the License.
15 */}}
16 apiVersion: apps/v1beta1
17 kind: StatefulSet
18 metadata:
19   name: {{ include "common.fullname" . }}
20   namespace: {{ include "common.namespace" . }}
21   labels:
22     app: {{ include "common.name" . }}
23     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
24     release: {{ include "common.release" . }}
25     heritage: {{ .Release.Service }}
26 spec:
27   serviceName: {{ .Values.service.name }}
28   replicas: {{ .Values.replicaCount }}
29   template:
30     metadata:
31       labels:
32         app: {{ include "common.name" . }}
33         release: {{ include "common.release" . }}
34     spec:
35       initContainers:
36       - command:
37         - /bin/sh
38         - -c
39         - |
40           chown -R 26:26 /podroot/;
41           chmod 700 /podroot/;
42         image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.busyboxImage }}
43         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
44         name: {{ include "common.name" . }}-prepare
45         volumeMounts:
46         - name: {{ include "common.fullname" . }}-data
47           mountPath: /podroot/
48       containers:
49       - name: {{ include "common.name" . }}
50         image: "{{ .Values.postgresRepository }}/{{ .Values.image }}"
51         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
52         ports:
53         - containerPort: {{ .Values.service.internalPort }}
54           name: postgres
55         # disable liveness probe when breakpoints set in debugger
56         # so K8s doesn't restart unresponsive container
57         {{- if eq .Values.liveness.enabled true }}
58         livenessProbe:
59           tcpSocket:
60             port: {{ .Values.service.internalPort }}
61           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
62           periodSeconds: {{ .Values.liveness.periodSeconds }}
63           timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
64         {{end -}}
65         readinessProbe:
66           tcpSocket:
67             port: {{ .Values.service.internalPort }}
68           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
69           periodSeconds: {{ .Values.readiness.periodSeconds }}
70         env:
71         - name: PGHOST
72           value: /tmp
73         - name: PG_PRIMARY_USER
74           value: primaryuser
75         - name: PG_MODE
76           value: set
77         - name: PG_PRIMARY_HOST
78           value: "{{.Values.container.name.primary}}"
79         - name: PG_REPLICA_HOST
80           value: "{{.Values.container.name.replica}}"
81         - name: PG_PRIMARY_PORT
82           value: "{{.Values.service.internalPort}}"
83         - name: PG_PRIMARY_PASSWORD
84           valueFrom:
85             secretKeyRef:
86               name: {{ template "common.fullname" . }}
87               key: pg-primary-password
88         - name: PG_USER
89           value: "{{.Values.config.pgUserName}}"
90         - name: PG_PASSWORD
91           valueFrom:
92             secretKeyRef:
93               name: {{ template "common.fullname" . }}
94               key: pg-user-password
95         - name: PG_DATABASE
96           value: "{{.Values.config.pgDatabase}}"
97         - name: PG_ROOT_PASSWORD
98           valueFrom:
99             secretKeyRef:
100               name: {{ template "common.fullname" . }}
101               key: pg-root-password
102         volumeMounts:
103         - mountPath: /pgdata
104           name: {{ include "common.fullname" . }}-data
105         - mountPath: /backup
106           name: {{ include "common.fullname" . }}-backup
107           readOnly: true
108         resources:
109 {{ include "common.resources" . | indent 12 }}
110         {{- if .Values.nodeSelector }}
111         nodeSelector:
112 {{ toYaml .Values.nodeSelector | indent 10 }}
113         {{- end -}}
114         {{- if .Values.affinity }}
115         affinity:
116 {{ toYaml .Values.affinity | indent 10 }}
117         {{- end }}
118       volumes:
119       - name: localtime
120         hostPath:
121           path: /etc/localtime
122       - name: {{ include "common.fullname" . }}-backup
123         emptyDir: {}
124 {{- if not .Values.persistence.enabled }}
125       - name: {{ include "common.fullname" . }}-data
126         emptyDir: {}
127 {{- else }}
128   volumeClaimTemplates:
129   - metadata:
130       name: {{ include "common.fullname" . }}-data
131       labels:
132         name: {{ include "common.fullname" . }}
133         chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
134         release: "{{ include "common.release" . }}"
135         heritage: "{{ .Release.Service }}"
136     spec:
137       accessModes:
138       - {{ .Values.persistence.accessMode | quote }}
139       storageClassName: {{ include "common.storageClass" . }}
140       resources:
141         requests:
142           storage: {{ .Values.persistence.size | quote }}
143 {{- end }}