[bitnami/kafka] Add topics provisioning job (#4783)

* WIP: Add test provisioning job

* Bump chart version

* Add provisioning image tpl

* Rename job, remove namespace from bootstrapServer

* Fix printf

* Trying to fix int printf

* Add helm hook annotations

* Update values

* Add labels, annotations, resources, provisioning fullname tpl, valome mounts, fix indentation

* Fix indentation

* Add resources to production values

* Kafka volumePermissions in provisioning job

* Stop execution on error and reschedule pod

* Add wait-for-port init container

* Add runAsHook for helm template

* Add comment for runAsHook

* Remove provisioning helper and runAsHook

* Add echo before each topic creation
This commit is contained in:
Sergey Shaykhullin
2021-01-18 20:49:58 +03:00
committed by GitHub
parent 69f97fbb68
commit 971ed6d8e1
5 changed files with 211 additions and 1 deletions

View File

@@ -29,4 +29,4 @@ name: kafka
sources:
- https://github.com/bitnami/bitnami-docker-kafka
- https://kafka.apache.org/
version: 12.5.0
version: 12.6.0

View File

@@ -46,6 +46,13 @@ Return the proper Kafka image name
{{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
{{- end -}}
{{/*
Return the proper Kafka provisioning image name
*/}}
{{- define "kafka.provisioning.image" -}}
{{ include "common.images.image" (dict "imageRoot" .Values.provisioning.image "global" .Values.global) }}
{{- end -}}
{{/*
Return the proper image name (for the init container auto-discovery image)
*/}}

View File

@@ -0,0 +1,109 @@
{{- if .Values.provisioning.enabled }}
kind: Job
apiVersion: batch/v1
metadata:
name: {{ include "kafka.fullname" . }}-provisioning
labels: {{- include "common.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: kafka
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
annotations:
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-delete-policy: before-hook-creation
{{- if .Values.commonAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
template:
metadata:
labels: {{- include "common.labels.standard" . | nindent 8 }}
app.kubernetes.io/component: kafka
{{- if .Values.podLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
{{- end }}
annotations:
spec:
{{- include "kafka.imagePullSecrets" . | indent 6 }}
restartPolicy: OnFailure
terminationGracePeriodSeconds: 0
initContainers:
- name: wait-for-available-kafka
image: {{ include "kafka.provisioning.image" . }}
imagePullPolicy: {{ .Values.provisioning.image.pullPolicy | quote }}
command:
- /bin/bash
- -c
- >-
set -e;
wait-for-port \
--host={{ include "kafka.fullname" . }} \
--state=inuse \
--timeout=120 \
{{ .Values.service.port | int64 }};
echo "Kafka is available";
containers:
- name: kafka-provisioning
image: {{ include "kafka.provisioning.image" . }}
imagePullPolicy: {{ .Values.provisioning.image.pullPolicy | quote }}
command:
- /bin/bash
- -c
- >-
set -e;
{{- $bootstrapServer := printf "%s:%d" (include "kafka.fullname" .) (.Values.service.port | int64) }}
{{- range $topic := .Values.provisioning.topics }}
echo "Ensure topic '{{ $topic.name }}' exists";
/opt/bitnami/kafka/bin/kafka-topics.sh \
--create \
--if-not-exists \
--bootstrap-server {{ $bootstrapServer }} \
--replication-factor {{ $topic.replicationFactor }} \
--partitions {{ $topic.partitions }} \
{{- range $name, $value := $topic.config }}
--config {{ $name }}={{ $value }} \
{{- end }}
--topic {{ $topic.name }};
{{- end }}
echo "Provisioning succeeded";
env:
- name: BITNAMI_DEBUG
value: {{ ternary "true" "false" .Values.provisioning.image.debug | quote }}
{{- if .Values.provisioning.resources }}
resources: {{- toYaml .Values.provisioning.resources | nindent 12 }}
{{- end }}
volumeMounts:
{{- if or .Values.config .Values.existingConfigmap }}
- name: kafka-config
mountPath: {{ .Values.persistence.mountPath }}/config/server.properties
subPath: server.properties
{{- end }}
{{- if or .Values.log4j .Values.existingLog4jConfigMap }}
- name: log4j-config
mountPath: {{ .Values.persistence.mountPath }}/config/log4j.properties
subPath: log4j.properties
{{- end }}
{{- if (include "kafka.tlsEncryption" .) }}
- name: kafka-certificates
mountPath: /certs
readOnly: true
{{- end }}
volumes:
{{- if or .Values.config .Values.existingConfigmap }}
- name: kafka-config
configMap:
name: {{ include "kafka.configmapName" . }}
{{- end }}
{{- if or .Values.log4j .Values.existingLog4jConfigMap }}
- name: log4j-config
configMap:
name: {{ include "kafka.log4j.configMapName" . }}
{{ end }}
{{- if (include "kafka.tlsEncryption" .) }}
- name: kafka-certificates
secret:
secretName: {{ include "kafka.jksSecretName" . }}
defaultMode: 256
{{- end }}
{{- end }}

View File

@@ -753,6 +753,53 @@ rbac:
##
create: false
## Kafka provisioning
##
provisioning:
enabled: false
image:
registry: docker.io
repository: bitnami/kafka
tag: 2.6.0-debian-10-r106
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace)
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## Example:
## pullSecrets:
## - myRegistryKeySecretName
##
pullSecrets: []
## Set to true if you would like to see extra information on logs
##
debug: false
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits: {}
# cpu: 250m
# memory: 1Gi
requests: {}
# cpu: 250m
# memory: 256Mi
topics: []
# - name: topic-name
# partitions: 3
# replicationFactor: 3
# # https://kafka.apache.org/documentation/#topicconfigs
# config:
# max.message.bytes: 64000
# flush.messages: 1
## Prometheus Exporters / Metrics
##
metrics:

View File

@@ -759,6 +759,53 @@ rbac:
##
create: false
## Kafka provisioning
##
provisioning:
enabled: false
image:
registry: docker.io
repository: bitnami/kafka
tag: 2.7.0-debian-10-r10
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace)
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## Example:
## pullSecrets:
## - myRegistryKeySecretName
##
pullSecrets: []
## Set to true if you would like to see extra information on logs
##
debug: false
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits: {}
# cpu: 250m
# memory: 1Gi
requests: {}
# cpu: 250m
# memory: 256Mi
topics: []
# - name: topic-name
# partitions: 1
# replicationFactor: 1
# # https://kafka.apache.org/documentation/#topicconfigs
# config:
# max.message.bytes: 64000
# flush.messages: 1
## Prometheus Exporters / Metrics
##
metrics: