Skip to content

Automate in-cluster tests #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ That's it. Just add business value :wink:.
For clients we tend to use [librdkafka](https://github.com/edenhill/librdkafka)-based drivers like [node-rdkafka](https://github.com/Blizzard/node-rdkafka).
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.
Don't forget the [addon](https://github.com/Yolean/kubernetes-kafka/labels/addon)s.

# Tests

```
kubectl apply -f test/
# Anything that isn't READY here is a failed test
kubectl -n test-kafka get pods -l test-target=kafka,test-type=readiness -w
```
5 changes: 5 additions & 0 deletions test/00namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: test-kafka
25 changes: 0 additions & 25 deletions test/11topic-create-test1.yml

This file was deleted.

27 changes: 0 additions & 27 deletions test/12topic-create-test2.yml

This file was deleted.

24 changes: 0 additions & 24 deletions test/21consumer-test1.yml

This file was deleted.

24 changes: 0 additions & 24 deletions test/31producer-test1.yml

This file was deleted.

15 changes: 0 additions & 15 deletions test/99testclient.yml

This file was deleted.

89 changes: 89 additions & 0 deletions test/basic-produce-consume.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
kind: ConfigMap
metadata:
name: basic-produce-consume
namespace: test-kafka
apiVersion: v1
data:

setup.sh: |-
touch /tmp/testlog

./bin/kafka-topics.sh --zookeeper $ZOOKEEPER \
--create --if-not-exists --topic test-basic-with-kafkacat \
--partitions 1 --replication-factor 1

# Despite the deprecation warning --zookeeper nothing is consumed when using --bootstrap-server
./bin/kafka-console-consumer.sh --zookeeper $ZOOKEEPER --topic test-basic-produce-consume > /tmp/testconsumed &

tail -f /tmp/testlog

continue.sh: |-
exit 0

run.sh: |-
exec >> /tmp/testlog
exec 2>&1

unique=$(date -Ins)

echo "Test $unique" | ./bin/kafka-console-producer.sh --broker-list $BOOTSTRAP --topic test-basic-produce-consume
echo ""
tail -n 1 /tmp/testconsumed | grep $unique

# How to make this test fail:
#apt-get update && apt-get install -y --no-install-recommends procps
#pkill java

exit 0

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: basic-produce-consume
namespace: test-kafka
spec:
replicas: 1
template:
metadata:
labels:
test-target: kafka
test-type: readiness
spec:
containers:
- name: testcase
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
env:
- name: BOOTSTRAP
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
- name: ZOOKEEPER
value: zookeeper.kafka.svc.cluster.local:2181
# Test set up
command:
- /bin/bash
- -e
- /test/setup.sh
# Test run, again and again
readinessProbe:
exec:
command:
- /bin/bash
- -e
- /test/run.sh
# JVM start is slow, can we keep producer started and restore the default preriod 10s?
periodSeconds: 30
# Test quit on nonzero exit
livenessProbe:
exec:
command:
- /bin/bash
- -e
- /test/continue.sh
volumeMounts:
- name: config
mountPath: /test
volumes:
- name: config
configMap:
name: basic-produce-consume
103 changes: 103 additions & 0 deletions test/basic-with-kafkacat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
kind: ConfigMap
metadata:
name: basic-with-kafkacat
namespace: test-kafka
apiVersion: v1
data:

setup.sh: |-
touch /tmp/testlog
tail -f /tmp/testlog

continue.sh: |-
exit 0

run.sh: |-
exec >> /tmp/testlog
exec 2>&1

unique=$(date -Ins)

echo "Test $unique" | kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -e | grep $unique

exit 0

---
apiVersion: batch/v1
kind: Job
metadata:
name: basic-with-kafkacat
namespace: test-kafka
spec:
template:
spec:
containers:
- name: topic-create
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
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: basic-with-kafkacat
namespace: test-kafka
spec:
replicas: 1
template:
metadata:
labels:
test-target: kafka
test-type: readiness
spec:
containers:
- name: testcase
# common test images
#image: solsson/curl@sha256:8b0927b81d10043e70f3e05e33e36fb9b3b0cbfcbccdb9f04fd53f67a270b874
image: solsson/kafkacat@sha256:1266d140c52cb39bf314b6f22b6d7a01c4c9084781bc779fdfade51214a713a8
#image: solsson/kubectl-kafkacat@sha256:3715a7ede3f168f677ee6faf311ff6887aff31f660cfeecad5d87b4f18516321
env:
- name: BOOTSTRAP
#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
value: kafka-0.broker.kafka.svc.cluster.local:9092
- name: ZOOKEEPER
value: zookeeper.kafka.svc.cluster.local:2181
# Test set up
command:
- /bin/bash
- -e
- /test/setup.sh
# Test run, again and again
readinessProbe:
exec:
command:
- /bin/bash
- -e
- /test/run.sh
# Test quit on nonzero exit
livenessProbe:
exec:
command:
- /bin/bash
- -e
- /test/continue.sh
volumeMounts:
- name: config
mountPath: /test
volumes:
- name: config
configMap:
name: basic-with-kafkacat
34 changes: 0 additions & 34 deletions test/test.sh

This file was deleted.