57bfdbf700270d8071b0bf0713cb3d18db388745
[oom.git] / kubernetes / common / postgres / 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: {{ .Release.Name }}
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: {{ .Release.Name }}
34     spec:
35       initContainers:
36       - command:
37         - /bin/sh
38         - -c
39         - |
40           for i in $(seq 0 $(({{ .Values.replicaCount }}-1))); do
41             if [ ! -d /podroot/data$i ]; then
42               mkdir -p /podroot/data$i;
43               chown 26:26 /podroot/data$i;
44               chmod 700 /podroot/data$i;
45             fi;
46           done
47         env:
48         - name: POD_NAME
49           valueFrom: { fieldRef: { fieldPath: metadata.name } }
50         securityContext:
51           privileged: true
52         image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.busyboxImage }}
53         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
54         name: init-sysctl
55         volumeMounts:
56         - name: {{ include "common.fullname" . }}-init
57           mountPath: /podroot/
58       containers:
59       - name: {{ include "common.name" . }}
60         image: "{{ .Values.postgresRepository }}/{{ .Values.image }}"
61         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
62         ports:
63         - containerPort: {{ .Values.service.internalPort }}
64           name: postgres
65         # disable liveness probe when breakpoints set in debugger
66         # so K8s doesn't restart unresponsive container
67         {{- if eq .Values.liveness.enabled true }}
68         livenessProbe:
69           tcpSocket:
70             port: {{ .Values.service.internalPort }}
71           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
72           periodSeconds: {{ .Values.liveness.periodSeconds }}
73           timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
74         {{end -}}
75         readinessProbe:
76           tcpSocket:
77             port: {{ .Values.service.internalPort }}
78           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
79           periodSeconds: {{ .Values.readiness.periodSeconds }}
80         env:
81         - name: PGHOST
82           value: /tmp
83         - name: PG_PRIMARY_USER
84           value: primaryuser
85         - name: PG_MODE
86           value: set
87         - name: PG_PRIMARY_HOST
88           value: "{{.Values.container.name.primary}}"
89         - name: PG_REPLICA_HOST
90           value: "{{.Values.container.name.replica}}"
91         - name: PG_PRIMARY_PORT
92           value: "{{.Values.service.internalPort}}"
93         - name: PG_PRIMARY_PASSWORD
94           valueFrom:
95             secretKeyRef:
96               name: {{ template "common.fullname" . }}
97               key: pg-primary-password
98         - name: PG_USER
99           value: "{{.Values.config.pgUserName}}"
100         - name: PG_PASSWORD
101           valueFrom:
102             secretKeyRef:
103               name: {{ template "common.fullname" . }}
104               key: pg-user-password
105         - name: PG_DATABASE
106           value: "{{.Values.config.pgDatabase}}"
107         - name: PG_ROOT_PASSWORD
108           valueFrom:
109             secretKeyRef:
110               name: {{ template "common.fullname" . }}
111               key: pg-root-password
112         volumeMounts:
113         - mountPath: /pgdata
114           name: {{ include "common.fullname" . }}-data
115         - mountPath: /backup
116           name: {{ include "common.fullname" . }}-backup
117           readOnly: true
118         resources:
119 {{ toYaml .Values.resources | indent 12 }}
120         {{- if .Values.nodeSelector }}
121         nodeSelector:
122 {{ toYaml .Values.nodeSelector | indent 10 }}
123         {{- end -}}
124         {{- if .Values.affinity }}
125         affinity:
126 {{ toYaml .Values.affinity | indent 10 }}
127         {{- end }}
128       volumes:
129       - name: localtime
130         hostPath:
131           path: /etc/localtime
132       - name: {{ include "common.fullname" . }}-init
133         hostPath:
134           path: {{ .Values.global.persistence.mountPath | default .Values.persistence.mountPath }}/{{ .Release.Name }}/{{ .Values.persistence.mountInitPath }}
135       - name: {{ include "common.fullname" . }}-backup
136         emptyDir: {}
137 #{{ if not .Values.persistence.enabled }}
138       - name: {{ include "common.fullname" . }}-data
139         emptyDir: {}
140 #{{ else }}
141   volumeClaimTemplates:
142   - metadata:
143       name: {{ include "common.fullname" . }}-data
144       labels:
145         name: {{ include "common.fullname" . }}
146     spec:
147       accessModes: [ {{ .Values.persistence.accessMode }} ]
148       storageClassName: {{ include "common.fullname" . }}-data
149       resources:
150         requests:
151           storage: {{ .Values.persistence.size }}
152 #{{ end }}