Skip to content

Commit cabe9be

Browse files
authored
Merge pull request #51 from Yolean/test-driven-kubernetes-concept
Automate in-cluster tests
2 parents b581659 + 48bd7c3 commit cabe9be

10 files changed

+205
-149
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ That's it. Just add business value :wink:.
5151
For clients we tend to use [librdkafka](https://github.com/edenhill/librdkafka)-based drivers like [node-rdkafka](https://github.com/Blizzard/node-rdkafka).
5252
To use [Kafka Connect](http://kafka.apache.org/documentation/#connect) and [Kafka Streams](http://kafka.apache.org/documentation/streams/) you may want to take a look at our [sample](https://github.com/solsson/dockerfiles/tree/master/connect-files) [Dockerfile](https://github.com/solsson/dockerfiles/tree/master/streams-logfilter)s.
5353
Don't forget the [addon](https://github.com/Yolean/kubernetes-kafka/labels/addon)s.
54+
55+
# Tests
56+
57+
```
58+
kubectl apply -f test/
59+
# Anything that isn't READY here is a failed test
60+
kubectl -n test-kafka get pods -l test-target=kafka,test-type=readiness -w
61+
```

test/00namespace.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: test-kafka

test/11topic-create-test1.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/12topic-create-test2.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/21consumer-test1.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/31producer-test1.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/99testclient.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/basic-produce-consume.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
kind: ConfigMap
3+
metadata:
4+
name: basic-produce-consume
5+
namespace: test-kafka
6+
apiVersion: v1
7+
data:
8+
9+
setup.sh: |-
10+
touch /tmp/testlog
11+
12+
./bin/kafka-topics.sh --zookeeper $ZOOKEEPER \
13+
--create --if-not-exists --topic test-basic-with-kafkacat \
14+
--partitions 1 --replication-factor 1
15+
16+
# Despite the deprecation warning --zookeeper nothing is consumed when using --bootstrap-server
17+
./bin/kafka-console-consumer.sh --zookeeper $ZOOKEEPER --topic test-basic-produce-consume > /tmp/testconsumed &
18+
19+
tail -f /tmp/testlog
20+
21+
continue.sh: |-
22+
exit 0
23+
24+
run.sh: |-
25+
exec >> /tmp/testlog
26+
exec 2>&1
27+
28+
unique=$(date -Ins)
29+
30+
echo "Test $unique" | ./bin/kafka-console-producer.sh --broker-list $BOOTSTRAP --topic test-basic-produce-consume
31+
echo ""
32+
tail -n 1 /tmp/testconsumed | grep $unique
33+
34+
# How to make this test fail:
35+
#apt-get update && apt-get install -y --no-install-recommends procps
36+
#pkill java
37+
38+
exit 0
39+
40+
---
41+
apiVersion: apps/v1beta1
42+
kind: Deployment
43+
metadata:
44+
name: basic-produce-consume
45+
namespace: test-kafka
46+
spec:
47+
replicas: 1
48+
template:
49+
metadata:
50+
labels:
51+
test-target: kafka
52+
test-type: readiness
53+
spec:
54+
containers:
55+
- name: testcase
56+
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
57+
env:
58+
- name: BOOTSTRAP
59+
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
60+
- name: ZOOKEEPER
61+
value: zookeeper.kafka.svc.cluster.local:2181
62+
# Test set up
63+
command:
64+
- /bin/bash
65+
- -e
66+
- /test/setup.sh
67+
# Test run, again and again
68+
readinessProbe:
69+
exec:
70+
command:
71+
- /bin/bash
72+
- -e
73+
- /test/run.sh
74+
# JVM start is slow, can we keep producer started and restore the default preriod 10s?
75+
periodSeconds: 30
76+
# Test quit on nonzero exit
77+
livenessProbe:
78+
exec:
79+
command:
80+
- /bin/bash
81+
- -e
82+
- /test/continue.sh
83+
volumeMounts:
84+
- name: config
85+
mountPath: /test
86+
volumes:
87+
- name: config
88+
configMap:
89+
name: basic-produce-consume

test/basic-with-kafkacat.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
kind: ConfigMap
3+
metadata:
4+
name: basic-with-kafkacat
5+
namespace: test-kafka
6+
apiVersion: v1
7+
data:
8+
9+
setup.sh: |-
10+
touch /tmp/testlog
11+
tail -f /tmp/testlog
12+
13+
continue.sh: |-
14+
exit 0
15+
16+
run.sh: |-
17+
exec >> /tmp/testlog
18+
exec 2>&1
19+
20+
unique=$(date -Ins)
21+
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
24+
25+
exit 0
26+
27+
---
28+
apiVersion: batch/v1
29+
kind: Job
30+
metadata:
31+
name: basic-with-kafkacat
32+
namespace: test-kafka
33+
spec:
34+
template:
35+
spec:
36+
containers:
37+
- name: topic-create
38+
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
39+
command:
40+
- ./bin/kafka-topics.sh
41+
- --zookeeper
42+
- zookeeper.kafka.svc.cluster.local:2181
43+
- --create
44+
- --if-not-exists
45+
- --topic
46+
- test-basic-with-kafkacat
47+
- --partitions
48+
- "1"
49+
- --replication-factor
50+
- "1"
51+
restartPolicy: Never
52+
---
53+
apiVersion: apps/v1beta1
54+
kind: Deployment
55+
metadata:
56+
name: basic-with-kafkacat
57+
namespace: test-kafka
58+
spec:
59+
replicas: 1
60+
template:
61+
metadata:
62+
labels:
63+
test-target: kafka
64+
test-type: readiness
65+
spec:
66+
containers:
67+
- name: testcase
68+
# common test images
69+
#image: solsson/curl@sha256:8b0927b81d10043e70f3e05e33e36fb9b3b0cbfcbccdb9f04fd53f67a270b874
70+
image: solsson/kafkacat@sha256:1266d140c52cb39bf314b6f22b6d7a01c4c9084781bc779fdfade51214a713a8
71+
#image: solsson/kubectl-kafkacat@sha256:3715a7ede3f168f677ee6faf311ff6887aff31f660cfeecad5d87b4f18516321
72+
env:
73+
- 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+
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+
command:
80+
- /bin/bash
81+
- -e
82+
- /test/setup.sh
83+
# Test run, again and again
84+
readinessProbe:
85+
exec:
86+
command:
87+
- /bin/bash
88+
- -e
89+
- /test/run.sh
90+
# Test quit on nonzero exit
91+
livenessProbe:
92+
exec:
93+
command:
94+
- /bin/bash
95+
- -e
96+
- /test/continue.sh
97+
volumeMounts:
98+
- name: config
99+
mountPath: /test
100+
volumes:
101+
- name: config
102+
configMap:
103+
name: basic-with-kafkacat

test/test.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)