[DMAAP] DMaaP ServiceMesh compatibility
[oom.git] / kubernetes / dmaap / components / message-router / components / message-router-kafka / templates / statefulset.yaml
1 {{/*
2 # Modifications Copyright © 2018 AT&T
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
17 apiVersion: apps/v1
18 kind: StatefulSet
19 metadata:
20   name: {{ include "common.fullname" . }}
21   namespace: {{ include "common.namespace" . }}
22   labels:
23     app: {{ include "common.name" . }}
24     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25     release: {{ include "common.release" . }}
26     heritage: {{ .Release.Service }}
27 spec:
28   selector:
29     matchLabels:
30       app: {{ include "common.name" . }}
31   serviceName: {{ .Values.service.name }}
32   replicas: {{ .Values.replicaCount }}
33   podManagementPolicy: Parallel
34   template:
35     metadata:
36       labels:
37         app:  {{ include "common.name" . }}
38         release: {{ include "common.release" . }}
39       {{- if .Values.prometheus.jmx.enabled }}
40       annotations:
41         prometheus.io/scrape: "true"
42         prometheus.io/port: {{ .Values.prometheus.jmx.port | quote }}
43       {{- end }}
44     spec:
45       {{- if .Values.nodeAffinity }}
46       nodeAffinity:
47       {{ toYaml .Values.nodeAffinity | indent 10 }}
48       {{- end }}
49       imagePullSecrets:
50       - name: "{{ include "common.namespace" . }}-docker-registry-key"
51       initContainers:
52       - command:
53         - /app/ready.py
54         args:
55         - --container-name
56         - {{ .Values.zookeeper.name }}
57         env:
58         - name: NAMESPACE
59           valueFrom:
60             fieldRef:
61               apiVersion: v1
62               fieldPath: metadata.namespace
63         image: {{ include "repositoryGenerator.image.readiness" . }}
64         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
65         name: {{ include "common.name" . }}-readiness
66       - command:
67         -  sh
68         - -exec
69         - |
70           rm -rf '/var/lib/kafka/data/lost+found';
71           chown -R 1000:0 /var/lib/kafka/data;
72         image: {{ include "repositoryGenerator.image.busybox" . }}
73         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
74         volumeMounts:
75         - mountPath: /var/lib/kafka/data
76           name: kafka-data
77         name: {{ include "common.name" . }}-permission-fixer
78       - command:
79         - sh
80         args:
81         - -c
82         - "cd /config-input  && for PFILE in `ls -1 .`; do envsubst <${PFILE} >/etc/kafka/secrets/jaas/${PFILE}; done"
83         env:
84         - name: ZK_ADMIN
85           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "zk-client" "key" "login") | indent 10 }}
86         - name: ZK_PSWD
87           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "zk-client" "key" "password") | indent 10 }}
88         - name: KAFKA_ADMIN
89           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "kafka-admin" "key" "login") | indent 10 }}
90         - name: KAFKA_PSWD
91           {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "kafka-admin" "key" "password") | indent 10 }}
92         volumeMounts:
93         - mountPath: /etc/kafka/secrets/jaas
94           name: jaas-config
95         - mountPath: /config-input
96           name: jaas
97         image: {{ include "repositoryGenerator.image.envsubst" . }}
98         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
99         name: {{ include "common.name" . }}-update-config
100       {{ include "common.certInitializer.initContainer" . | indent 6 | trim }}
101       containers:
102       {{- if .Values.prometheus.jmx.enabled }}
103       - name: prometheus-jmx-exporter
104         image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.prometheus.jmx.image }}:{{ .Values.prometheus.jmx.imageTag }}
105         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
106         command:
107         - java
108         - -XX:+UnlockExperimentalVMOptions
109         - -XX:+UseCGroupMemoryLimitForHeap
110         - -XX:MaxRAMFraction=1
111         - -XshowSettings:vm
112         - -jar
113         - jmx_prometheus_httpserver.jar
114         - {{ .Values.prometheus.jmx.port | quote }}
115         - /etc/jmx-kafka/jmx-kafka-prometheus.yml
116         ports:
117         - containerPort: {{ .Values.prometheus.jmx.port }}
118         resources:
119 {{ toYaml .Values.prometheus.jmx.resources | indent 10 }}
120         volumeMounts:
121         - name: jmx-config
122           mountPath: /etc/jmx-kafka
123       {{- end }}
124       - name: {{ include "common.name" .  }}
125         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
126         imagePullPolicy:  {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
127         command:
128         - sh
129         - -exc
130         - |
131           export KAFKA_BROKER_ID=${HOSTNAME##*-} && \
132           {{- if  .Values.global.aafEnabled }}
133           cp {{ .Values.certInitializer.credsPath }}/{{ .Values.certInitializer.final_cadi_files }} /etc/kafka/data/{{ .Values.certInitializer.final_cadi_files }} && \
134           export KAFKA_ADVERTISED_LISTENERS=EXTERNAL_SASL_PLAINTEXT://$(HOST_IP):$(( $KAFKA_BROKER_ID + {{ .Values.service.baseNodePort }} )),INTERNAL_SASL_PLAINTEXT://:{{ .Values.service.internalPort }} && \
135           {{ else }}
136           export KAFKA_ADVERTISED_LISTENERS=EXTERNAL_PLAINTEXT://$(HOST_IP):$(( $KAFKA_BROKER_ID + {{ .Values.service.baseNodePort }} )),INTERNAL_PLAINTEXT://:{{ .Values.service.internalPort }} && \
137           {{- end }}
138           exec /etc/confluent/docker/run
139         resources:
140 {{ include "common.resources" . | indent 12 }}
141         ports:
142         - containerPort: {{ .Values.service.internalPort }}
143         - containerPort: {{ .Values.service.externalPort }}
144         {{- if .Values.prometheus.jmx.enabled }}
145         - containerPort: {{ .Values.jmx.port }}
146           name: jmx
147         {{- end }}
148         {{ if eq .Values.liveness.enabled true }}
149         livenessProbe:
150           tcpSocket:
151             port: {{ .Values.service.internalPort }}
152           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
153           periodSeconds: {{ .Values.liveness.periodSeconds }}
154           timeoutSeconds: {{ .Values.liveness.timeoutSeconds }}
155         {{ end }}
156         readinessProbe:
157           tcpSocket:
158             port: {{ .Values.service.internalPort }}
159           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
160           periodSeconds: {{ .Values.readiness.periodSeconds }}
161           timeoutSeconds: {{ .Values.readiness.timeoutSeconds }}
162         env:
163         - name: HOST_IP
164           valueFrom:
165             fieldRef:
166               apiVersion: v1
167               fieldPath: status.hostIP
168         - name: KAFKA_ZOOKEEPER_CONNECT
169           value: "{{ include "common.kafkaNodes" (dict "dot" . "replicaCount" .Values.zookeeper.replicaCount "componentName" .Values.zookeeper.name "port" .Values.zookeeper.port ) }}"
170         - name: KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE
171           value: "{{ .Values.kafka.enableSupport }}"
172         - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
173           value: "{{ .Values.config.offsets_topic_replication_factor | default .Values.replicaCount }}"
174         - name: KAFKA_NUM_PARTITIONS
175           value: "{{ .Values.config.num_partition | default .Values.replicaCount }}"
176         - name:  KAFKA_DEFAULT_REPLICATION_FACTOR
177           value: "{{ .Values.config.default_replication_factor | default .Values.replicaCount }}"
178         {{- if  .Values.global.aafEnabled }}
179         - name: KAFKA_OPTS
180           value: "{{ .Values.kafka.jaasOptionsAaf }}"
181         - name: aaf_locate_url
182           value: https://aaf-locate.{{ include "common.namespace" . }}:8095
183         - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
184           value: "{{ .Values.kafka.protocolMapAaf }}"
185         - name: KAFKA_LISTENERS
186           value: "{{ .Values.kafka.listenersAaf }}"
187         - name: KAFKA_SASL_ENABLED_MECHANISMS
188           value: "{{ .Values.kafka.saslMech }}"
189         - name: KAFKA_INTER_BROKER_LISTENER_NAME
190           value: "{{ .Values.kafka.interBrokerListernerAaf }}"
191         - name: KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL
192           value: "{{ .Values.kafka.saslInterBrokerProtocol }}"
193         - name: KAFKA_AUTHORIZER_CLASS_NAME
194           value: "{{ .Values.kafka.authorizer }}"
195         {{ else }}
196         - name: KAFKA_OPTS
197           value: "{{ .Values.kafka.jaasOptions }}"
198         - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
199           value: "{{ .Values.kafka.protocolMap }}"
200         - name: KAFKA_LISTENERS
201           value: "{{ .Values.kafka.listeners }}"
202         - name: KAFKA_INTER_BROKER_LISTENER_NAME
203           value: "{{ .Values.kafka.interBrokerListerner }}"
204         {{- end }}
205         {{- range $key, $value := .Values.configurationOverrides }}
206         - name: {{ printf "KAFKA_%s" $key | replace "." "_" | upper | quote }}
207           value: {{ $value | quote }}
208         {{- end }}
209         {{- if .Values.jmx.port }}
210         - name: KAFKA_JMX_PORT
211           value: "{{ .Values.jmx.port }}"
212         {{- end }}
213         - name: enableCadi
214           value: "{{ .Values.global.aafEnabled }}"
215         volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 8 }}
216         - mountPath: /etc/localtime
217           name: localtime
218           readOnly: true
219         - mountPath: /var/run/docker.sock
220           name: docker-socket
221         - name: jaas-config
222           mountPath: /etc/kafka/secrets/jaas
223         - mountPath: /var/lib/kafka/data
224           name: kafka-data
225       {{- if .Values.tolerations }}
226       tolerations:
227         {{ toYaml .Values.tolerations | indent 10 }}
228       {{- end }}
229       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
230       volumes:  {{ include "common.certInitializer.volumes" . | nindent 6 }}
231       - name: localtime
232         hostPath:
233           path: /etc/localtime
234       - name: jaas-config
235         emptyDir:
236           medium: Memory
237       - name: docker-socket
238         hostPath:
239           path: /var/run/docker.sock
240       - name: jaas
241         configMap:
242           name: {{ include "common.fullname" . }}-jaas-configmap
243       {{- if .Values.prometheus.jmx.enabled }}
244       - name: jmx-config
245         configMap:
246           name: {{ include "common.fullname" . }}-prometheus-configmap
247       {{- end }}
248 {{ if not .Values.persistence.enabled }}
249       - name: kafka-data
250         emptyDir: {}
251 {{ else }}
252   volumeClaimTemplates:
253     - metadata:
254         name: kafka-data
255         labels:
256           app: {{ include "common.fullname" . }}
257           chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
258           release: "{{ include "common.release" . }}"
259           heritage: "{{ .Release.Service }}"
260       spec:
261         accessModes:
262           - {{ .Values.persistence.accessMode | quote }}
263         storageClassName: {{ include "common.storageClass" . }}
264         resources:
265           requests:
266             storage: {{ .Values.persistence.size | quote }}
267 {{ end }}