blob: 2d2ee81a05c77ca771770e00b8a6ffd29a17ae35 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
---
kind: ConfigMap
metadata:
name: test-basic-with-kafkacat
namespace: test-kafka
apiVersion: v1
data:
setup.sh: |-
touch /tmp/testlog
tail -f /tmp/testlog
test.sh: |-
exec >> /tmp/testlog
exec 2>&1
PC_WAIT=.2
MAX_AGE=5
UNIQUE="${HOSTNAME}@$(date -u -Ins)"
echo "Test $UNIQUE" >> /shared/produce.tmp
sleep $PC_WAIT
LAST=$(tail -n 1 /shared/consumed.tmp)
LAST_TS=$(echo $LAST | awk -F';' '{print $1}')
LAST_MSG=$(echo $LAST | awk -F';' '{print $4}')
NOW=$(date -u +%s%3N)
DIFF_S=$((($NOW - $LAST_TS)/1000))
DIFF_MS=$((($NOW - $LAST_TS)%1000))
#echo "$NOW ($(date +%FT%H:%M:%S.%3N)):"
#echo "$LAST_TS"
if [ $DIFF_S -gt $MAX_AGE ]; then
echo "Last message is $DIFF_S.$DIFF_MS old:"
echo "$LAST_MSG"
exit 10
fi
if [[ "$LAST_MSG" != *"$UNIQUE" ]]; then
echo "Last message (at $LAST_TS) isn't from this test run ($UNIQUE):"
echo "$LAST_MSG"
exit 11
fi
# get info about this message
kafkacat -Q -b $BOOTSTRAP -t test-basic-with-kafkacat:0:$LAST_TS \
-X socket.timeout.ms=600 -X session.timeout.ms=300 -X request.timeout.ms=50 -X metadata.request.timeout.ms=600
[ $? -eq 0 ] || echo "At $(date +%FT%H:%M:%S.%3N) bootstrap broker(s) might be down"
# but don't fail the test; producer and consumer should keep going if there are other brokers
# We haven't asserted that the consumer works, so we'll just have to assume that it will exit if it fails
exit 0
quit-on-nonzero-exit.sh: |-
exec >> /tmp/testlog
exec 2>&1
exit 0
---
apiVersion: batch/v1
kind: Job
metadata:
name: test-basic-with-kafkacat
namespace: test-kafka
spec:
template:
spec:
containers:
- name: topic-create
image: solsson/kafka:0.11.0.1@sha256:1b6b25ea30a93d0d9dc69eb4531d7246d72df4015bbb5baa5bb551a77011bed5
command:
- ./bin/kafka-topics.sh
- --zookeeper
- zookeeper.kafka.svc.cluster.local:2181
- --create
- --if-not-exists
- --topic
- test-basic-with-kafkacat
- --partitions
- "1"
- --replication-factor
- "1"
restartPolicy: Never
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-basic-with-kafkacat
namespace: test-kafka
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
test-target: kube-test
test-type: readiness
# for example:
# readonly - can be used in production
# isolated - read/write but in a manner that does not affect other services
# load - unsuitable for production because it uses significant resources
# chaos - unsuitable for production because it injects failure modes
#test-use:
spec:
containers:
- name: producer
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
env:
- name: BOOTSTRAP
value: kafka-0.broker.kafka.svc.cluster.local:9092
command:
- /bin/bash
- -cex
- >
echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp
;
tail -f /shared/produce.tmp |
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T -d broker
;
volumeMounts:
- name: config
mountPath: /test
- name: shared
mountPath: /shared
- name: consumer
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
env:
- name: BOOTSTRAP
value: kafka-0.broker.kafka.svc.cluster.local:9092
command:
- /bin/bash
- -cex
- >
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T;%p;%o;%s\n' -u -d broker |
tee /shared/consumed.tmp
;
volumeMounts:
- name: config
mountPath: /test
- name: shared
mountPath: /shared
- name: testcase
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
env:
- name: BOOTSTRAP
value: kafka-0.broker.kafka.svc.cluster.local:9092
command:
- /bin/bash
- -e
- /test/setup.sh
readinessProbe:
exec:
command:
- /bin/bash
- -e
- /test/test.sh
initialDelaySeconds: 10
periodSeconds: 10
livenessProbe:
exec:
command:
- /bin/bash
- -e
- /test/quit-on-nonzero-exit.sh
volumeMounts:
- name: config
mountPath: /test
- name: shared
mountPath: /shared
volumes:
- name: config
configMap:
name: test-basic-with-kafkacat
- name: shared
emptyDir: {}
|