aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsolsson <solsson@gmail.com>2017-11-09 15:04:51 +0100
committerGitHub <noreply@github.com>2017-11-09 15:04:51 +0100
commit6b24807de8286ecfb9bf47fe1c269816920dec73 (patch)
tree75a8dbb4eb9d637d5ff455f3db353f57eecdd1e6
parent3867c84447d583d3b51dac79a1b9e597db7b7458 (diff)
parent75e3db4e7ab2a62546d82b3ee19e295e7142320c (diff)
downloadkubernetes-kafka-6b24807de8286ecfb9bf47fe1c269816920dec73.tar.gz
kubernetes-kafka-6b24807de8286ecfb9bf47fe1c269816920dec73.tar.bz2
kubernetes-kafka-6b24807de8286ecfb9bf47fe1c269816920dec73.zip
Merge pull request #79 from Yolean/bootstrap-test
Update tests to act as long-running consumers
-rw-r--r--README.md2
-rw-r--r--test/basic-produce-consume.yml113
-rw-r--r--test/basic-with-kafkacat.yml102
-rw-r--r--test/kafkacat.yml181
-rw-r--r--test/produce-consume.yml166
5 files changed, 348 insertions, 216 deletions
diff --git a/README.md b/README.md
index 9d382c8..2f007cc 100644
--- a/README.md
+++ b/README.md
@@ -78,5 +78,5 @@ Like the rest of this repo they have `kubectl` as the only local dependency.
```
kubectl apply -f test/
# Anything that isn't READY here is a failed test
-kubectl get pods -l test-target=kafka,test-type=readiness -w --all-namespaces
+kubectl get pods -l test-type=readiness -w --namespace=test-kafka
```
diff --git a/test/basic-produce-consume.yml b/test/basic-produce-consume.yml
deleted file mode 100644
index 32ec4ec..0000000
--- a/test/basic-produce-consume.yml
+++ /dev/null
@@ -1,113 +0,0 @@
----
-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-produce-consume \
- --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: batch/v1
-kind: Job
-metadata:
- name: basic-produce-consume
- namespace: test-kafka
-spec:
- template:
- spec:
- containers:
- - name: topic-create
- image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
- command:
- - ./bin/kafka-topics.sh
- - --zookeeper
- - zookeeper.kafka.svc.cluster.local:2181
- - --create
- - --if-not-exists
- - --topic
- - test-basic-produce-consume
- - --partitions
- - "1"
- - --replication-factor
- - "2"
- restartPolicy: Never
----
-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:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
- 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
deleted file mode 100644
index 78e423c..0000000
--- a/test/basic-with-kafkacat.yml
+++ /dev/null
@@ -1,102 +0,0 @@
----
-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:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
- 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
- - "2"
- 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:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
- #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/kafkacat.yml b/test/kafkacat.yml
new file mode 100644
index 0000000..61a265c
--- /dev/null
+++ b/test/kafkacat.yml
@@ -0,0 +1,181 @@
+---
+kind: ConfigMap
+metadata:
+ name: 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 "${UNIQUE: -41:5}: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-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: topic-test-kafkacat
+ namespace: test-kafka
+spec:
+ template:
+ spec:
+ containers:
+ - name: topic-create
+ image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
+ command:
+ - ./bin/kafka-topics.sh
+ - --zookeeper
+ - zookeeper.kafka.svc.cluster.local:2181
+ - --create
+ - --if-not-exists
+ - --topic
+ - test-kafkacat
+ - --partitions
+ - "1"
+ - --replication-factor
+ - "2"
+ restartPolicy: Never
+---
+apiVersion: apps/v1beta2
+kind: ReplicaSet
+metadata:
+ name: kafkacat
+ namespace: test-kafka
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ test-target: kafka-client-kafkacat
+ test-type: readiness
+ template:
+ metadata:
+ labels:
+ test-target: kafka-client-kafkacat
+ 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:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
+ 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-kafkacat -v -T -d broker -K ':'
+ ;
+ volumeMounts:
+ - name: config
+ mountPath: /test
+ - name: shared
+ mountPath: /shared
+ - name: consumer
+ image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
+ env:
+ - name: BOOTSTRAP
+ value: kafka-0.broker.kafka.svc.cluster.local:9092
+ command:
+ - /bin/bash
+ - -cex
+ - >
+ kafkacat -C -b $BOOTSTRAP -t test-kafkacat -o -1 -f '%T;%k:%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:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
+ env:
+ - name: BOOTSTRAP
+ value: bootstrap.kafka: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: kafkacat
+ - name: shared
+ emptyDir: {}
diff --git a/test/produce-consume.yml b/test/produce-consume.yml
new file mode 100644
index 0000000..a326f01
--- /dev/null
+++ b/test/produce-consume.yml
@@ -0,0 +1,166 @@
+---
+kind: ConfigMap
+metadata:
+ name: produce-consume
+ namespace: test-kafka
+apiVersion: v1
+data:
+
+ setup.sh: |-
+ touch /tmp/testlog
+
+ tail -f /tmp/testlog
+
+ test.sh: |-
+ exec >> /tmp/testlog
+ exec 2>&1
+
+ # As low as in kafkacat based test didn't work, but this value can likely be squeezed
+ PC_WAIT=2.0
+
+ UNIQUE="${HOSTNAME}@$(date -u -Ins)"
+
+ echo "Test $UNIQUE" >> /shared/produce.tmp
+ sleep $PC_WAIT
+ LAST=$(tail -n 1 /shared/consumed.tmp)
+ [ -z "$LAST" ] && echo "Nothing consumed yet" && exit 1
+
+ # Haven't found how to get message timestamp in console-consumer, see kafkacat based test instead
+ LAST_MSG=$LAST
+
+ if [[ "$LAST_MSG" != *"$UNIQUE" ]]; then
+ echo "Last message (at $(date +%FT%T)) isn't from this test run ($UNIQUE):"
+ echo "$LAST_MSG"
+ exit 11
+ fi
+
+ echo "OK ($LAST_MSG at $(date +%FT%T))"
+ # 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: topic-test-produce-consume
+ namespace: test-kafka
+spec:
+ template:
+ spec:
+ containers:
+ - name: topic-create
+ image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
+ command:
+ - ./bin/kafka-topics.sh
+ - --zookeeper
+ - zookeeper.kafka.svc.cluster.local:2181
+ - --create
+ - --if-not-exists
+ - --topic
+ - test-produce-consume
+ - --partitions
+ - "1"
+ - --replication-factor
+ - "2"
+ restartPolicy: Never
+---
+apiVersion: apps/v1beta2
+kind: ReplicaSet
+metadata:
+ name: produce-consume
+ namespace: test-kafka
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ test-target: kafka-client-console
+ test-type: readiness
+ template:
+ metadata:
+ labels:
+ test-target: kafka-client-console
+ 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/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
+ 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 |
+ ./bin/kafka-console-producer.sh --broker-list $BOOTSTRAP --topic test-produce-consume
+ ;
+ volumeMounts:
+ - name: config
+ mountPath: /test
+ - name: shared
+ mountPath: /shared
+ - name: consumer
+ image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
+ env:
+ - name: BOOTSTRAP
+ value: kafka-0.broker.kafka.svc.cluster.local:9092
+ command:
+ - /bin/bash
+ - -cex
+ - >
+ ./bin/kafka-console-consumer.sh --bootstrap-server $BOOTSTRAP --topic test-produce-consume |
+ 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: produce-consume
+ - name: shared
+ emptyDir: {}