|
| 1 | +apiVersion: batch/v1 |
| 2 | +kind: Job |
| 3 | +metadata: |
| 4 | + name: replication-factor-increase |
| 5 | + namespace: kafka |
| 6 | +spec: |
| 7 | + template: |
| 8 | + metadata: |
| 9 | + name: replication-factor-increase |
| 10 | + spec: |
| 11 | + containers: |
| 12 | + - name: kafka |
| 13 | + image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d |
| 14 | + env: |
| 15 | + - name: ZOOKEEPER |
| 16 | + value: zookeeper.kafka:2181 |
| 17 | + # the following must be edited per job |
| 18 | + - name: TOPICS |
| 19 | + value: "" |
| 20 | + - name: BROKERS |
| 21 | + value: 0,1,2 |
| 22 | + command: |
| 23 | + - /bin/bash |
| 24 | + - -ce |
| 25 | + - > |
| 26 | + if [ -z "$TOPICS" ]; then |
| 27 | + echo "Please set the TOPICS env (comma-separated) and re-create the job" |
| 28 | + tail -f /dev/null |
| 29 | + fi |
| 30 | +
|
| 31 | + echo '{"topics":[' > /tmp/reassign-topics.json; |
| 32 | + echo -n ' {"topic":"' >> /tmp/reassign-topics.json; |
| 33 | + echo -n $TOPICS | sed 's/,/"},\n {"topic":"/g' >> /tmp/reassign-topics.json; |
| 34 | + echo '"}' >> /tmp/reassign-topics.json; |
| 35 | + echo ']}' >> /tmp/reassign-topics.json; |
| 36 | +
|
| 37 | + echo "# reassign-topics.json"; |
| 38 | + cat /tmp/reassign-topics.json; |
| 39 | +
|
| 40 | + ./bin/kafka-reassign-partitions.sh |
| 41 | + --zookeeper=$ZOOKEEPER |
| 42 | + --generate |
| 43 | + --topics-to-move-json-file=/tmp/reassign-topics.json |
| 44 | + --broker-list=$BROKERS > /tmp/generated.txt; |
| 45 | +
|
| 46 | + tail -n 1 /tmp/generated.txt > /tmp/proposed-reassignment.json; |
| 47 | +
|
| 48 | + sleep 1; |
| 49 | + echo "# proposed-reassignment.json"; |
| 50 | + cat /tmp/proposed-reassignment.json; |
| 51 | +
|
| 52 | + sed -i 's/"replicas":\[.\]/"replicas":[0,1,2]/g' /tmp/proposed-reassignment.json; |
| 53 | + sed -i 's/,"log_dirs":\["any"\]//g' /tmp/proposed-reassignment.json; |
| 54 | + echo "# proposed-reassignment.json modified to affect replication factor"; |
| 55 | + cat /tmp/proposed-reassignment.json; |
| 56 | +
|
| 57 | + echo "# Triggering kafka-reassign-partitions.sh" |
| 58 | + ./bin/kafka-reassign-partitions.sh |
| 59 | + --zookeeper=$ZOOKEEPER |
| 60 | + --execute |
| 61 | + --reassignment-json-file=/tmp/proposed-reassignment.json; |
| 62 | +
|
| 63 | + echo "# Reassignment exited. Upon success you may want to run preferred-replica-election." |
| 64 | + restartPolicy: Never |
| 65 | + backoffLimit: 3 |
0 commit comments