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