Skip to content

Commit c1a133d

Browse files
committed
improve resource/topic wait script
1 parent dc1c7fe commit c1a133d

1 file changed

Lines changed: 82 additions & 1 deletion

File tree

demos/data-lakehouse-iceberg-trino-spark/create-spark-ingestion-job.yaml

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
spec:
1212
serviceAccountName: demo-serviceaccount
1313
initContainers:
14-
- name: wait-for-kafka
14+
- name: wait-for-resources
1515
image: oci.stackable.tech/sdp/tools:1.0.0-stackable0.0.0-dev
1616
command:
1717
- bash
@@ -23,6 +23,68 @@ spec:
2323
kubectl wait --for=condition=ready --timeout=30m pod -l app=minio,release=minio,stackable.tech/vendor=Stackable
2424
echo 'Waiting for all kafka brokers to be ready'
2525
kubectl wait --for=condition=ready --timeout=30m pod -l app.kubernetes.io/name=kafka,app.kubernetes.io/instance=kafka
26+
echo 'Waiting for all nifi instances to be ready'
27+
kubectl wait --for=condition=ready --timeout=30m pod -l app.kubernetes.io/name=nifi,app.kubernetes.io/instance=nifi
28+
- name: wait-for-kafka-topics
29+
image: oci.stackable.tech/sdp/kafka:3.9.1-stackable0.0.0-dev
30+
command:
31+
- bash
32+
- -euo
33+
- pipefail
34+
- -c
35+
- |
36+
# Configurable
37+
BROKER="${BROKER:-kafka-broker-default-0-listener-broker:9093}"
38+
39+
log() {
40+
level="$1"
41+
shift
42+
echo "[$level] $*"
43+
}
44+
45+
check_leaders() {
46+
local topic=$1
47+
local failed=0
48+
49+
log INFO "Starting leader check on Kafka broker: $BROKER for topic: $topic"
50+
metadata=$(kcat -b "$BROKER" -X security.protocol=SSL -X ssl.key.location=/stackable/tls-kcat/tls.key -X ssl.certificate.location=/stackable/tls-kcat/tls.crt -X ssl.ca.location=/stackable/tls-kcat/ca.crt -L -t "$topic" 2>/dev/null)
51+
52+
if [[ -z "$metadata" ]]; then
53+
log ERROR "Failed to retrieve metadata for topic: $topic"
54+
return 1
55+
fi
56+
57+
log DEBUG "Metadata for $topic:"
58+
echo "$metadata"
59+
60+
if echo "$metadata" | grep -q 'leader: -1'; then
61+
log ERROR "Found 'leader: -1' in topic '$topic'; topic not ready yet!"
62+
return 1
63+
fi
64+
65+
if echo "$metadata" | grep -q 'Broker: Leader not available'; then
66+
log ERROR "Topic '$topic' not available yet"
67+
return 1
68+
fi
69+
70+
log INFO "Check topic '$topic' was successful"
71+
return 0
72+
}
73+
74+
for topic in "shared_bikes_bike_status" "shared_bikes_station_status" "shared_bikes_station_information" "water_levels_measurements" "water_levels_stations"
75+
do
76+
result=$(check_leaders "$topic")
77+
echo "$result"
78+
if [ "$result" == "1" ]
79+
then
80+
exit 1
81+
fi
82+
done
83+
exit 0
84+
85+
volumeMounts:
86+
- name: tls-kcat
87+
mountPath: /stackable/tls-kcat
2688
containers:
2789
- name: create-spark-ingestion-job
2890
image: oci.stackable.tech/sdp/tools:1.0.0-stackable0.0.0-dev
@@ -40,7 +102,26 @@ spec:
40102
- name: manifest
41103
configMap:
42104
name: create-spark-ingestion-job-manifest
105+
- name: tls-kcat
106+
ephemeral:
107+
volumeClaimTemplate:
108+
metadata:
109+
annotations:
110+
secrets.stackable.tech/backend.autotls.cert.lifetime: "1d"
111+
secrets.stackable.tech/class: "tls"
112+
secrets.stackable.tech/format: "tls-pem"
113+
secrets.stackable.tech/scope: "pod"
114+
spec:
115+
accessModes:
116+
- ReadWriteOnce
117+
resources:
118+
requests:
119+
storage: "1"
120+
storageClassName: secrets.stackable.tech
121+
volumeMode: Filesystem
43122
restartPolicy: OnFailure
123+
securityContext:
124+
fsGroup: 1000
44125
backoffLimit: 50
45126
---
46127
apiVersion: v1

0 commit comments

Comments
 (0)