aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsolsson <solsson@gmail.com>2017-07-28 21:27:12 +0200
committerGitHub <noreply@github.com>2017-07-28 21:27:12 +0200
commitcabe9be47c347d428d816ca0034223021c15c024 (patch)
treea5882577cf1577c0413d25e5b5229d8abec257ea
parentb58165916ff156082c8ed8ea08a8c68c1506efdc (diff)
parent48bd7c39af657db1338662cf99b5531aac929d1d (diff)
downloadkubernetes-kafka-cabe9be47c347d428d816ca0034223021c15c024.tar.gz
kubernetes-kafka-cabe9be47c347d428d816ca0034223021c15c024.tar.bz2
kubernetes-kafka-cabe9be47c347d428d816ca0034223021c15c024.zip
Merge pull request #51 from Yolean/test-driven-kubernetes-concept
Automate in-cluster tests
-rw-r--r--README.md8
-rw-r--r--test/00namespace.yml5
-rw-r--r--test/11topic-create-test1.yml25
-rw-r--r--test/12topic-create-test2.yml27
-rw-r--r--test/21consumer-test1.yml24
-rw-r--r--test/31producer-test1.yml24
-rw-r--r--test/99testclient.yml15
-rw-r--r--test/basic-produce-consume.yml89
-rw-r--r--test/basic-with-kafkacat.yml103
-rw-r--r--test/test.sh34
10 files changed, 205 insertions, 149 deletions
diff --git a/README.md b/README.md
index 2c747dc..6464906 100644
--- a/README.md
+++ b/README.md
@@ -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
+```
diff --git a/test/00namespace.yml b/test/00namespace.yml
new file mode 100644
index 0000000..fbb6e0e
--- /dev/null
+++ b/test/00namespace.yml
@@ -0,0 +1,5 @@
+---
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: test-kafka
diff --git a/test/11topic-create-test1.yml b/test/11topic-create-test1.yml
deleted file mode 100644
index 321dc57..0000000
--- a/test/11topic-create-test1.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-apiVersion: batch/v1
-kind: Job
-metadata:
- name: topic-create-test1
- namespace: kafka
-spec:
- template:
- metadata:
- name: topic-create-test1
- spec:
- containers:
- - name: kafka
- image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
- command:
- - ./bin/kafka-topics.sh
- - --zookeeper
- - zookeeper:2181
- - --create
- - --topic
- - test1
- - --partitions
- - "1"
- - --replication-factor
- - "1"
- restartPolicy: Never
diff --git a/test/12topic-create-test2.yml b/test/12topic-create-test2.yml
deleted file mode 100644
index edbe1df..0000000
--- a/test/12topic-create-test2.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-apiVersion: batch/v1
-kind: Job
-metadata:
- name: topic-create-test2
- namespace: kafka
-spec:
- template:
- metadata:
- name: topic-create-test2
- spec:
- containers:
- - name: kafka
- image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
- command:
- - ./bin/kafka-topics.sh
- - --zookeeper
- - zookeeper:2181
- - --create
- - --topic
- - test2
- - --partitions
- - "1"
- - --replication-factor
- - "3"
- - --config
- - min.insync.replicas=2
- restartPolicy: Never
diff --git a/test/21consumer-test1.yml b/test/21consumer-test1.yml
deleted file mode 100644
index 43678f8..0000000
--- a/test/21consumer-test1.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-apiVersion: extensions/v1beta1
-kind: Deployment
-metadata:
- name: consumer-test1
- namespace: kafka
-spec:
- replicas: 1
- template:
- metadata:
- labels:
- app: consumer
- scope: test
- topic: test1
- spec:
- containers:
- - name: kafka
- image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
- command:
- - ./bin/kafka-console-consumer.sh
- - --bootstrap-server
- - kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092,kafka-2.broker.kafka.svc.cluster.local:9092
- - --topic
- - test1
- - --from-beginning
diff --git a/test/31producer-test1.yml b/test/31producer-test1.yml
deleted file mode 100644
index 354a16a..0000000
--- a/test/31producer-test1.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-apiVersion: batch/v1
-kind: Job
-metadata:
- name: producer-test1
- namespace: kafka
-spec:
- template:
- metadata:
- name: producer-test1
- spec:
- containers:
- - name: kafka
- image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
- command:
- - /bin/sh
- - -c
- - >
- echo "test1 $(date)"
- |
- ./bin/kafka-console-producer.sh
- --topic test1
- --broker-list kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092,kafka-2.broker.kafka.svc.cluster.local:9092
- ; sleep 1
- restartPolicy: Never
diff --git a/test/99testclient.yml b/test/99testclient.yml
deleted file mode 100644
index a367004..0000000
--- a/test/99testclient.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-# Kafka image without the service, so you can run ./bin/ stuff
-# kubectl exec -ti testclient -- /bin/bash
-apiVersion: v1
-kind: Pod
-metadata:
- name: testclient
- namespace: kafka
-spec:
- containers:
- - name: kafka
- image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
- command:
- - sh
- - -c
- - "exec tail -f /dev/null"
diff --git a/test/basic-produce-consume.yml b/test/basic-produce-consume.yml
new file mode 100644
index 0000000..f56a01f
--- /dev/null
+++ b/test/basic-produce-consume.yml
@@ -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
diff --git a/test/basic-with-kafkacat.yml b/test/basic-with-kafkacat.yml
new file mode 100644
index 0000000..a8974e8
--- /dev/null
+++ b/test/basic-with-kafkacat.yml
@@ -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
diff --git a/test/test.sh b/test/test.sh
deleted file mode 100644
index bfc4a8f..0000000
--- a/test/test.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-
-# List topics
-kubectl exec testclient -- ./bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
-
-# Create topic
-kubectl exec testclient -- ./bin/kafka-topics.sh --zookeeper zookeeper:2181 --topic test1 --create --partitions 1 --replication-factor 1
-
-# Set one of your terminals to listen to messages on the test topic
-kubectl exec -ti testclient -- ./bin/kafka-console-consumer.sh --zookeeper zookeeper:2181 --topic test1 --from-beginning
-
-# Go ahead and produce messages
-echo "Write a message followed by enter, exit using Ctrl+C"
-kubectl exec -ti testclient -- ./bin/kafka-console-producer.sh --broker-list kafka-0.broker.kafka.svc.cluster.local:9092 --topic test1
-
-# Bootstrap even if two nodes are down (shorter name requires same namespace)
-kubectl exec -ti testclient -- ./bin/kafka-console-producer.sh --broker-list kafka-0.broker:9092,kafka-1.broker:9092,kafka-2.broker:9092 --topic test1
-
-# The following commands run in the pod
-kubectl exec -ti testclient -- /bin/bash
-
-# Topic 2, replicated
-./bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic test2
-
-./bin/kafka-verifiable-consumer.sh \
- --broker-list=kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092 \
- --topic=test2 --group-id=A --verbose
-
-# If a topic isn't available this producer will tell you
-# WARN Error while fetching metadata with correlation id X : {topicname=LEADER_NOT_AVAILABLE}
-# ... but with current config Kafka will auto-create the topic
-./bin/kafka-verifiable-producer.sh \
- --broker-list=kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092 \
- --value-prefix=1 --topic=test2 \
- --acks=1 --throughput=1 --max-messages=10