057ed664cfa88c6551ed7d7ca2124a0fc320957d
[it/dep.git] / ric-aux / 80-Auxiliary-Functions / helm / kong / charts / kong / charts / postgresql / templates / statefulset-slaves.yaml
1 {{- if .Values.replication.enabled }}
2 apiVersion: apps/v1beta2
3 kind: StatefulSet
4 metadata:
5   name: "{{ template "postgresql.fullname" . }}-slave"
6   labels:
7     app: {{ template "postgresql.name" . }}
8     chart: {{ template "postgresql.chart" . }}
9     release: {{ .Release.Name | quote }}
10     heritage: {{ .Release.Service | quote }}
11 spec:
12   serviceName: {{ template "postgresql.fullname" . }}-headless
13   replicas: {{ .Values.replication.slaveReplicas }}
14   selector:
15     matchLabels:
16       app: {{ template "postgresql.name" . }}
17       release: {{ .Release.Name | quote }}
18       role: slave
19   template:
20     metadata:
21       name: {{ template "postgresql.fullname" . }}
22       labels:
23         app: {{ template "postgresql.name" . }}
24         chart: {{ template "postgresql.chart" . }}
25         release: {{ .Release.Name | quote }}
26         heritage: {{ .Release.Service | quote }}
27         role: slave
28     spec:
29       {{- if .Values.securityContext.enabled }}
30       securityContext:
31         fsGroup: {{ .Values.securityContext.fsGroup }}
32         runAsUser: {{ .Values.securityContext.runAsUser }}
33       {{- end }}
34       {{- if .Values.image.pullSecrets }}
35       imagePullSecrets:
36       {{- range .Values.image.pullSecrets }}
37         - name: {{ . }}
38       {{- end}}
39       {{- end }}
40       {{- if .Values.slave.nodeSelector }}
41       nodeSelector:
42 {{ toYaml .Values.slave.nodeSelector | indent 8 }}
43       {{- end }}
44       {{- if .Values.slave.affinity }}
45       affinity:
46 {{ toYaml .Values.slave.affinity | indent 8 }}
47       {{- end }}
48       {{- if .Values.slave.tolerations }}
49       tolerations:
50 {{ toYaml .Values.slave.tolerations | indent 8 }}
51       {{- end }}
52       {{- if .Values.terminationGracePeriodSeconds }}
53       terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
54       {{- end }}
55       {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
56       initContainers:
57       - name: init-chmod-data
58         image: {{ template "postgresql.volumePermissions.image" . }}
59         imagePullPolicy: "{{ .Values.volumePermissions.image.pullPolicy }}"
60         resources:
61 {{ toYaml .Values.resources | indent 10 }}
62         command:
63           - sh
64           - -c
65           - |
66             chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} /bitnami
67             if [ -d /bitnami/postgresql/data ]; then
68               chmod  0700 /bitnami/postgresql/data;
69             fi
70         securityContext:
71           runAsUser: {{ .Values.volumePermissions.securityContext.runAsUser }}
72         volumeMounts:
73         - name: data
74           mountPath: /bitnami/postgresql
75       {{- end }}
76       containers:
77       - name: {{ template "postgresql.fullname" . }}
78         image: {{ template "postgresql.image" . }}
79         imagePullPolicy: "{{ .Values.image.pullPolicy }}"
80         resources:
81 {{ toYaml .Values.resources | indent 10 }}
82         env:
83         {{- if .Values.image.debug}}
84         - name: BASH_DEBUG
85           value: "1"
86         - name: NAMI_DEBUG
87           value: "1"
88         {{- end }}
89         - name: POSTGRESQL_REPLICATION_MODE
90           value: "slave"
91         - name: POSTGRESQL_REPLICATION_USER
92           value: {{ .Values.replication.user | quote }}
93         {{- if .Values.usePasswordFile }}
94         - name: POSTGRESQL_REPLICATION_PASSWORD_FILE
95           value: "/opt/bitnami/postgresql/secrets/postgresql-replication-password"
96         {{- else }}
97         - name: POSTGRESQL_REPLICATION_PASSWORD
98           valueFrom:
99             secretKeyRef:
100               name: {{ template "postgresql.secretName" . }}
101               key: postgresql-replication-password
102         {{- end }}
103         - name: POSTGRESQL_CLUSTER_APP_NAME
104           value: {{ .Values.replication.applicationName }}
105         - name: POSTGRESQL_MASTER_HOST
106           value: {{ template "postgresql.fullname" . }}
107         - name: POSTGRESQL_MASTER_PORT_NUMBER
108           value: {{ .Values.service.port | quote }}
109         ports:
110         - name: postgresql
111           containerPort: {{ .Values.service.port }}
112         {{- if .Values.livenessProbe.enabled }}
113         livenessProbe:
114           exec:
115             command:
116             - sh
117             - -c
118            {{- if .Values.postgresqlDatabase }}
119             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -d {{ .Values.postgresqlDatabase | quote }} -h localhost
120            {{- else }}
121             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -h localhost
122            {{- end }}
123           initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
124           periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
125           timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
126           successThreshold: {{ .Values.livenessProbe.successThreshold }}
127           failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
128         {{- end }}
129         {{- if .Values.readinessProbe.enabled }}
130         readinessProbe:
131           exec:
132             command:
133             - sh
134             - -c
135            {{- if .Values.postgresqlDatabase }}
136             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -d {{ .Values.postgresqlDatabase | quote }} -h localhost
137            {{- else }}
138             - exec pg_isready -U {{ .Values.postgresqlUsername | quote }} -h localhost
139            {{- end }}
140           initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
141           periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
142           timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
143           successThreshold: {{ .Values.readinessProbe.successThreshold }}
144           failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
145         {{- end }}
146         volumeMounts:
147         {{- if .Values.usePasswordFile }}
148         - name: postgresql-password
149           mountPath: /opt/bitnami/postgresql/secrets
150         {{ end }}
151         {{- if .Values.persistence.enabled }}
152         - name: data
153           mountPath: {{ .Values.persistence.mountPath }}
154         {{ end }}
155         {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.extendedConfConfigMap }}
156         - name: postgresql-extended-config
157           mountPath: /bitnami/postgresql/conf/conf.d/
158         {{- end }}
159         {{- if or (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresqlConfiguration .Values.pgHbaConfiguration .Values.configurationConfigMap }}
160         - name: postgresql-config
161           mountPath: /bitnami/postgresql/conf
162         {{- end }}
163       volumes:
164       {{- if .Values.usePasswordFile }}
165       - name: postgresql-password
166         secret:
167           secretName: {{ template "postgresql.secretName" . }}
168       {{ end }}
169       {{- if or (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresqlConfiguration .Values.pgHbaConfiguration .Values.configurationConfigMap}}
170       - name: postgresql-config
171         configMap:
172           name: {{ template "postgresql.configurationCM" . }}
173       {{- end }}
174       {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.extendedConfConfigMap }}
175       - name: postgresql-extended-config
176         configMap:
177           name: {{ template "postgresql.extendedConfigurationCM" . }}
178       {{- end }}
179       {{- if not .Values.persistence.enabled }}
180       - name: data
181         emptyDir: {}
182       {{- end }}
183   updateStrategy:
184     type: {{ .Values.updateStrategy.type }}
185 {{- if .Values.persistence.enabled }}
186   volumeClaimTemplates:
187     - metadata:
188         name: data
189       {{- with .Values.persistence.annotations }}
190         annotations:
191         {{- range $key, $value := . }}
192           {{ $key }}: {{ $value }}
193         {{- end }}
194       {{- end }}
195       spec:
196         accessModes:
197         {{- range .Values.persistence.accessModes }}
198           - {{ . | quote }}
199         {{- end }}
200         resources:
201           requests:
202             storage: {{ .Values.persistence.size | quote }}
203       {{- if .Values.persistence.storageClass }}
204       {{- if (eq "-" .Values.persistence.storageClass) }}
205         storageClassName: ""
206       {{- else }}
207         storageClassName: "{{ .Values.persistence.storageClass }}"
208       {{- end }}
209       {{- end }}
210 {{- end }}
211 {{- end }}