2
0

kafka-provisioning.yaml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {{- if .Values.provisioning.enabled }}
  2. kind: Job
  3. apiVersion: batch/v1
  4. metadata:
  5. name: {{ include "kafka.fullname" . }}-provisioning
  6. labels: {{- include "common.labels.standard" . | nindent 4 }}
  7. app.kubernetes.io/component: kafka-provisioning
  8. {{- if .Values.commonLabels }}
  9. {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  10. {{- end }}
  11. annotations:
  12. helm.sh/hook: post-install,post-upgrade
  13. helm.sh/hook-delete-policy: before-hook-creation
  14. {{- if .Values.commonAnnotations }}
  15. {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  16. {{- end }}
  17. spec:
  18. template:
  19. metadata:
  20. labels: {{- include "common.labels.standard" . | nindent 8 }}
  21. app.kubernetes.io/component: kafka-provisioning
  22. {{- if .Values.podLabels }}
  23. {{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
  24. {{- end }}
  25. annotations:
  26. {{- if .Values.provisioning.podAnnotations }}
  27. {{- include "common.tplvalues.render" (dict "value" .Values.provisioning.podAnnotations "context" $) | nindent 8 }}
  28. {{- end }}
  29. spec:
  30. {{- include "kafka.imagePullSecrets" . | nindent 6 }}
  31. {{- if .Values.provisioning.schedulerName }}
  32. schedulerName: {{ .Values.provisioning.schedulerName | quote }}
  33. {{- end }}
  34. restartPolicy: OnFailure
  35. terminationGracePeriodSeconds: 0
  36. initContainers:
  37. - name: wait-for-available-kafka
  38. image: {{ include "kafka.provisioning.image" . }}
  39. imagePullPolicy: {{ .Values.provisioning.image.pullPolicy | quote }}
  40. command:
  41. - /bin/bash
  42. - -c
  43. - >-
  44. set -e;
  45. wait-for-port \
  46. --host={{ include "kafka.fullname" . }} \
  47. --state=inuse \
  48. --timeout=120 \
  49. {{ .Values.service.port | int64 }};
  50. echo "Kafka is available";
  51. containers:
  52. - name: kafka-provisioning
  53. image: {{ include "kafka.provisioning.image" . }}
  54. imagePullPolicy: {{ .Values.provisioning.image.pullPolicy | quote }}
  55. command:
  56. {{- if .Values.provisioning.command }}
  57. {{- include "common.tplvalues.render" (dict "value" .Values.provisioning.command "context" $) | nindent 12 }}
  58. {{- else }}
  59. - /bin/bash
  60. {{- end }}
  61. args:
  62. {{- if .Values.provisioning.args }}
  63. {{- include "common.tplvalues.render" (dict "value" .Values.provisioning.args "context" $) | nindent 12 }}
  64. {{- else }}
  65. - -ec
  66. - |
  67. {{- $bootstrapServer := printf "%s:%d" (include "kafka.fullname" .) (.Values.service.port | int64) }}
  68. {{- range $topic := .Values.provisioning.topics }}
  69. echo "Ensure topic '{{ $topic.name }}' exists"
  70. /opt/bitnami/kafka/bin/kafka-topics.sh \
  71. --create \
  72. --if-not-exists \
  73. --bootstrap-server {{ $bootstrapServer }} \
  74. --replication-factor {{ $topic.replicationFactor | default $.Values.provisioning.replicationFactor }} \
  75. --partitions {{ $topic.partitions | default $.Values.provisioning.numPartitions }} \
  76. {{- range $name, $value := $topic.config }}
  77. --config {{ $name }}={{ $value }} \
  78. {{- end }}
  79. --topic {{ $topic.name }}
  80. {{- end }}
  81. echo "Provisioning succeeded"
  82. {{- end }}
  83. env:
  84. - name: BITNAMI_DEBUG
  85. value: {{ ternary "true" "false" .Values.provisioning.image.debug | quote }}
  86. {{- if .Values.provisioning.resources }}
  87. resources: {{- toYaml .Values.provisioning.resources | nindent 12 }}
  88. {{- end }}
  89. volumeMounts:
  90. {{- if or .Values.config .Values.existingConfigmap }}
  91. - name: kafka-config
  92. mountPath: {{ .Values.persistence.mountPath }}/config/server.properties
  93. subPath: server.properties
  94. {{- end }}
  95. {{- if or .Values.log4j .Values.existingLog4jConfigMap }}
  96. - name: log4j-config
  97. mountPath: {{ .Values.persistence.mountPath }}/config/log4j.properties
  98. subPath: log4j.properties
  99. {{- end }}
  100. {{- if (include "kafka.tlsEncryption" .) }}
  101. - name: kafka-certificates
  102. mountPath: /certs
  103. readOnly: true
  104. {{- end }}
  105. volumes:
  106. {{- if or .Values.config .Values.existingConfigmap }}
  107. - name: kafka-config
  108. configMap:
  109. name: {{ include "kafka.configmapName" . }}
  110. {{- end }}
  111. {{- if or .Values.log4j .Values.existingLog4jConfigMap }}
  112. - name: log4j-config
  113. configMap:
  114. name: {{ include "kafka.log4j.configMapName" . }}
  115. {{ end }}
  116. {{- if (include "kafka.tlsEncryption" .) }}
  117. - name: kafka-certificates
  118. secret:
  119. secretName: {{ include "kafka.tlsSecretName" . }}
  120. defaultMode: 256
  121. {{- end }}
  122. {{- end }}