Skip to content

Commit

Permalink
Removes kafkaList + updates to 29.3.14 + adds new test (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaspi authored Sep 24, 2024
1 parent 7f5831a commit 30b8030
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
7 changes: 3 additions & 4 deletions charts/kafka/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: kafka
description: Apache Kafka is an event streaming platform for streaming analytics, data integration.
icon: https://minio.lab.sspcloud.fr/projet-onyxia/assets/servicesImg/kafka.png
keyworks:
keywords:
- streaming
- messaging
home: https://kafka.apache.org/
Expand All @@ -28,12 +28,11 @@ version: 0.2.7
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1
appVersion: "1"
dependencies:
- name: kafka
version: 29.3.7
version: 30.1.4
repository: https://charts.bitnami.com/bitnami
enabled: true
- name: library-chart
version: 1.5.25
repository: https://inseefrlab.github.io/helm-charts-interactive-services
18 changes: 6 additions & 12 deletions charts/kafka/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
{{- $replicaCount := int .Values.kafka.replicaCount }}
{{- $portNumber := int .Values.kafka.service.ports.client }}
{{- $fullname := include "library-chart.fullname" . }}
{{- $fullname := include "common.names.fullname" .Subcharts.kafka }}
{{- $pvcList := list }}
{{- $kafkaList := list }}
{{- range $e, $i := until $replicaCount }}
{{- $pvcList = append $pvcList (printf "data-%s-%d" $fullname $i) }}
{{- $kafkaList = append $kafkaList (printf "%s-%d.%s-headless:%d" $fullname $i $fullname $portNumber) }}
{{- range $i := until $replicaCount }}
{{- $pvcList = append $pvcList (printf "data-%s-controller-%d" $fullname $i) }}
{{- end }}
- You can connect to this kafka only within the cluster itself.
- the connection string is :
```
**{{ (include "kafkaList" .)}}**
```
- the connection string is : `{{ $fullname }}:{{ .Values.kafka.service.ports.client }}`
- example for producer python :

```
from confluent_kafka import Producer
import socket

conf = {'bootstrap.servers': "{{ (include "kafkaList" .) }}",
conf = {'bootstrap.servers': "{{ $fullname }}:{{ .Values.kafka.service.ports.client }}",
'client.id': socket.gethostname()}

producer = Producer(conf)
Expand All @@ -29,4 +23,4 @@ producer = Producer(conf)
- **You can safely delete this chart and recreate one later**
- Data volumes will not be deleted
- If you start a new {{ .Chart.Name }}, it will reuse those volumes silently.
- If you want to delete those volume definitily : `kubectl delete pvc {{ join " " $pvcList }}`
- If you want to delete those volume definitely : `kubectl delete pvc {{ join " " $pvcList }}`
10 changes: 0 additions & 10 deletions charts/kafka/templates/_helpers.tpl

This file was deleted.

7 changes: 3 additions & 4 deletions charts/kafka/templates/discovery-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{{- if .Values.kafka.discoverable.allow }}
{{- $fullname := include "common.names.fullname" . }}
{{- $secretName := printf "%s-%s" "discoverable" $fullname -}}
{{- $fullname := include "common.names.fullname" .Subcharts.kafka -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ $secretName }}
name: discoverable-{{ $fullname }}
annotations:
onyxia/discovery: "kafka"
type: Opaque
data:
kafka-service: {{ (include "kafkaList" .) | b64enc | quote }}
kafka-service: {{ (printf "%s:%d" $fullname (.Values.kafka.service.ports.client | int)) | b64enc | quote }}
{{- end -}}
6 changes: 3 additions & 3 deletions charts/kafka/templates/tests/test-db-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ metadata:
spec:
containers:
- name: {{ include "library-chart.fullname" . }}-test-connection
image: "bitnami/kafka:3.6"
image: "bitnami/kafka:3.8"
env:
- name: HOST
value: {{ include "library-chart.fullname" . }}
command: ["sh", "-c", "/opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server {{ include "kafkaList" . }}"]
command: ["sh", "-c"]
args: ["/opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server {{ template "common.names.fullname" . }}:{{ .Values.kafka.service.ports.client }}"]
restartPolicy: Never

53 changes: 53 additions & 0 deletions charts/kafka/templates/tests/test-db-with-python-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "library-chart.fullname" . }}-test-confluent-kafka"
labels:
{{- include "library-chart.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": hook-succeeded
spec:
containers:
- name: {{ include "library-chart.fullname" . }}-test-confluent-kafka
image: "inseefrlab/onyxia-python-minimal"
command: ["/bin/sh","-c"]
args:
- |
pip3 install confluent-kafka && timeout 2m python3 <<EOF
from confluent_kafka import Producer, Consumer
import socket
kafka_server = "{{ template "common.names.fullname" . }}:{{ .Values.kafka.service.ports.client }}"
print("Setting up producer...")
pconf = {
'bootstrap.servers': kafka_server,
'client.id': socket.gethostname()
}
producer = Producer(pconf)
print("Sending message to topic `helm-test-kafka-db`...")
producer.produce("helm-test-kafka-db", key="Test result", value="Success!")
producer.flush()
print("Setting up consumer...")
cconf = {'bootstrap.servers': kafka_server,
'group.id': 'foo',
'auto.offset.reset': 'smallest'}
consumer = Consumer(cconf)
consumer.subscribe(["helm-test-kafka-db"])
print("Waiting message from topic `helm-test-kafka-db`...")
while True:
try:
msg = consumer.poll(1.0)
if msg is None:
continue
else:
print(msg.value())
exit(0)
except KeyboardInterrupt:
exit(1)
EOF
restartPolicy: Never
1 change: 0 additions & 1 deletion charts/kafka/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ kafka:
interbroker:
protocol: PLAINTEXT
fullnameOverride: kafka

0 comments on commit 30b8030

Please sign in to comment.