Skip to content

Commit aa00a49

Browse files
Fix Kafka generic function e2e verification
1 parent 46ac0d5 commit aa00a49

3 files changed

Lines changed: 105 additions & 3 deletions

File tree

.ci/helm.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,56 @@ function ci::verify_exclamation_function() {
371371
return 1
372372
}
373373

374+
function ci::ensure_kafka_topic() {
375+
topic=$1
376+
kafka_bootstrap_server=$2
377+
properties_file=$3
378+
kubectl exec -n ${NAMESPACE} kafka-client -- kafka-topics.sh \
379+
--bootstrap-server "${kafka_bootstrap_server}" \
380+
--create \
381+
--if-not-exists \
382+
--topic "${topic}" \
383+
--command-config "/opt/bitnami/kafka/config/${properties_file}" || true
384+
}
385+
386+
function ci::verify_kafka_exclamation_function() {
387+
inputtopic=$1
388+
outputtopic=$2
389+
inputmessage=$3
390+
outputmessage=$4
391+
kafka_bootstrap_server=$5
392+
properties_file=$6
393+
consumer_group="function-mesh-${RANDOM}-$(date +%s)"
394+
output_file=$(mktemp)
395+
396+
kubectl exec -n ${NAMESPACE} kafka-client -- kafka-console-consumer.sh \
397+
--bootstrap-server "${kafka_bootstrap_server}" \
398+
--consumer.config "/opt/bitnami/kafka/config/${properties_file}" \
399+
--topic "${outputtopic}" \
400+
--group "${consumer_group}" \
401+
--timeout-ms 30000 \
402+
--max-messages 1 > "${output_file}" &
403+
consumer_pid=$!
404+
405+
sleep 3
406+
kubectl exec -n ${NAMESPACE} kafka-client -- bash -c \
407+
"echo \"${inputmessage}\" | kafka-console-producer.sh --bootstrap-server ${kafka_bootstrap_server} --producer.config /opt/bitnami/kafka/config/${properties_file} --topic ${inputtopic}"
408+
409+
if ! wait "${consumer_pid}"; then
410+
cat "${output_file}" || true
411+
rm -f "${output_file}"
412+
return 1
413+
fi
414+
415+
MESSAGE=$(cat "${output_file}")
416+
rm -f "${output_file}"
417+
echo "$MESSAGE"
418+
if [[ "$MESSAGE" == *"$outputmessage"* ]]; then
419+
return 0
420+
fi
421+
return 1
422+
}
423+
374424
function ci::verify_exclamation_function_with_auth() {
375425
inputtopic=$1
376426
outputtopic=$2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: generic-kafka-client-config
5+
namespace: default
6+
data:
7+
kafka.properties: |
8+
security.protocol=PLAINTEXT
9+
---
10+
apiVersion: v1
11+
kind: Pod
12+
metadata:
13+
name: kafka-client
14+
namespace: default
15+
spec:
16+
containers:
17+
- name: kafka
18+
image: bitnamilegacy/kafka:3.4.1
19+
command: ["/bin/sh", "-c", "--"]
20+
args: ["while true; do sleep 30; done;"]
21+
volumeMounts:
22+
- name: config-volume
23+
mountPath: /opt/bitnami/kafka/config/kafka.properties
24+
subPath: kafka.properties
25+
readOnly: true
26+
volumes:
27+
- name: config-volume
28+
configMap:
29+
name: generic-kafka-client-config

.ci/tests/integration/cases/generic-kafka-function/verify.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,49 @@ if [ ! "$KUBECONFIG" ]; then
3333
fi
3434

3535
manifests_file="${BASE_DIR}"/.ci/tests/integration/cases/generic-kafka-function/manifests.yaml
36+
kafka_client_file="${BASE_DIR}"/.ci/tests/integration/cases/generic-kafka-function/kafka-client.yaml
37+
kafka_bootstrap_server=sn-platform-pulsar-broker-0.sn-platform-pulsar-broker.default.svc.cluster.local:9092
38+
kafka_properties_file=kafka.properties
39+
input_topic=input-kafka-topic
40+
output_topic=output-kafka-topic
41+
input_message="test-message-${RANDOM}-$(date +%s)"
42+
output_message="${input_message}!"
3643

44+
kubectl apply -f "${kafka_client_file}" > /dev/null 2>&1
45+
kubectl wait pod kafka-client --for=condition=Ready --timeout=2m || {
46+
kubectl get pod kafka-client -o yaml || true
47+
kubectl delete -f "${kafka_client_file}" > /dev/null 2>&1 || true
48+
exit 1
49+
}
50+
51+
ci::ensure_kafka_topic "${input_topic}" "${kafka_bootstrap_server}" "${kafka_properties_file}" > /dev/null 2>&1
52+
ci::ensure_kafka_topic "${output_topic}" "${kafka_bootstrap_server}" "${kafka_properties_file}" > /dev/null 2>&1
3753
kubectl apply -f "${manifests_file}" > /dev/null 2>&1
3854

3955
kubectl wait -l compute.functionmesh.io/name=generic-kafka-function --for=condition=Ready pod --timeout=2m || {
4056
kubectl get pods -l compute.functionmesh.io/name=generic-kafka-function
4157
kubectl logs -l compute.functionmesh.io/name=generic-kafka-function --tail=100 || true
4258
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
59+
kubectl delete -f "${kafka_client_file}" > /dev/null 2>&1 || true
4360
exit 1
4461
}
4562

63+
set +e
4664
verify_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} \
47-
ci::verify_exclamation_function "persistent://public/default/input-kafka-topic" \
48-
"persistent://public/default/output-kafka-topic" "test-message" "test-message!" 10 2>&1)
49-
if [ $? -eq 0 ]; then
65+
ci::verify_kafka_exclamation_function "${input_topic}" "${output_topic}" \
66+
"${input_message}" "${output_message}" "${kafka_bootstrap_server}" "${kafka_properties_file}" 2>&1)
67+
verify_status=$?
68+
set -e
69+
70+
if [ ${verify_status} -eq 0 ]; then
5071
echo "e2e-test: ok" | yq eval -
5172
else
5273
echo "$verify_result"
5374
kubectl logs -l compute.functionmesh.io/name=generic-kafka-function --tail=100 || true
5475
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
76+
kubectl delete -f "${kafka_client_file}" > /dev/null 2>&1 || true
5577
exit 1
5678
fi
5779

5880
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
81+
kubectl delete -f "${kafka_client_file}" > /dev/null 2>&1 || true

0 commit comments

Comments
 (0)