Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ spec:
${kafka_provisioning_commands[i]}
done
echo "Provisioning succeeded"

COMMON_OPTS="--bootstrap-server {{ $bootstrapServersString }} --command-config ${CLIENT_CONF}"

echo "Checking existing topic partitions and configs..."
{{- range $topics }}
{{- $partitions := .partitions | default $defaultPartitions }}
CURRENT_PARTITIONS=$(/opt/kafka/bin/kafka-topics.sh $COMMON_OPTS --describe --topic "{{ .name }}" 2>/dev/null | head -1 | sed -n 's/.*PartitionCount: \([0-9]*\).*/\1/p')
if [ -n "$CURRENT_PARTITIONS" ] && [ "{{ $partitions }}" -gt "$CURRENT_PARTITIONS" ]; then
echo " [ALTER] {{ .name }}: increasing partitions from $CURRENT_PARTITIONS to {{ $partitions }}"
/opt/kafka/bin/kafka-topics.sh $COMMON_OPTS --alter --topic "{{ .name }}" --partitions "{{ $partitions }}"
fi
{{- if .config }}
CURRENT_CONFIGS=$(/opt/kafka/bin/kafka-configs.sh $COMMON_OPTS --entity-type topics --entity-name "{{ .name }}" --describe 2>/dev/null || echo "")
NEEDS_UPDATE=false
{{- range $key, $value := .config }}
if ! echo "$CURRENT_CONFIGS" | grep -q '{{ $key }}={{ $value }}'; then
NEEDS_UPDATE=true
fi
{{- end }}
if [ "$NEEDS_UPDATE" = true ]; then
echo " [CONFIG] {{ .name }}: applying config updates"
{{- $scratch := dict "args" (list) }}
{{- range $key, $value := .config }}
{{- $_ := set $scratch "args" (append (index $scratch "args") (printf "%s=[%s]" $key $value)) }}
{{- end }}
/opt/kafka/bin/kafka-configs.sh $COMMON_OPTS --entity-type topics --entity-name "{{ .name }}" --alter --add-config '{{ join "," (index $scratch "args") }}' || echo " [CONFIG] {{ .name }}: WARNING - config update failed"
fi
{{- end }}
{{- end }}
echo "Update complete"
{{- if $provisioning.resources }}
resources:
{{ toYaml $provisioning.resources | indent 12 }}
Expand Down
Loading