Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit b633119

Browse files
authored
Adding Kafka Connect Test (#21)
* Updating README to reflect mTLS support * adding kafkaconnect test components * fixing bug in internaltest * removing extra logs from test
1 parent 84a1d1d commit b633119

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Currently Portworx must be installed manually due to the lack of a Helm chart. P
3131
## Future Work
3232

3333
- [ ] Work with Portworx on Helm Chart
34-
- [ ] Enable mTLS on ingress for Kafka load balancer
3534
- [ ] Enable volume encryption on Portworx volumes
3635
- [ ] Get past possible VNET issues in Terraform template
3736

test/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@ The test results will displayed at the end. The script with exit with code 0 for
2525
- `kafkacat` needs to be installed and added to $PATH
2626
- on systems with homebrew installed, you can run `brew install kafkacat`
2727
- [Kafkacat Installation](https://github.com/edenhill/kafkacat#install)
28+
- Optionally, Kafka Connect can be tested if there is a backing database for it.
29+
- Instructions can be found under the [kafka connect examples](../examples/kafka_connect)
30+
- After the test is run, you can check the collection for the test messages
2831

2932
### Running the test
3033

3134
Run the testing script as configured below:
3235
- If the External LoadBalancer is enabled with TLS support: `sh ./externaltest.sh -t`
3336
- If the External LoadBalancer is NOT enabled with TLS support: `sh ./externaltest.sh`
37+
- If kafkaconnect is enabled:
38+
- export three variables in your shell:
39+
```
40+
export MONGODB_CONN_URL='<mongodb-connection-string>'
41+
export DATABASE='<database-name>'
42+
export COLLECTION'<collection-name>'
43+
```
44+
- add the `-k` flag to the arguments: `sh ./externaltest.sh -t -k`
3445
3546
The script will deploy a test topic and connect to the brokers through the external loadbalancer IP, utilizing kafkacat as a producer and consumer.
3647
The test results will displayed at the end. The script with exit with code 0 for success and 1 for failure.

test/externaltest.sh

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@
44
YELLOW='\033[1;33m'
55
RED='\033[1;31m'
66
GREEN='\033[0;32m'
7+
CYAN='\033[0;36m'
78
NC='\033[0m' # No Color
89

10+
MTLS_ON=false
11+
K_CONNECT_ON=false
12+
13+
#### ARGS AND INPUTS
14+
while [ ! $# -eq 0 ]
15+
do
16+
case "$1" in
17+
-t)
18+
echo "${CYAN}mTLS/SSL Support enabled.${NC}"
19+
MTLS_ON=true
20+
;;
21+
-k)
22+
echo "${CYAN}Kafka Connect test enabled.${NC}"
23+
K_CONNECT_ON=true
24+
;;
25+
esac
26+
shift
27+
done
28+
929
#### FUNCTIONS --------------------------------
1030
create_and_deploy_kafka_test_topic_yaml()
1131
{
@@ -62,6 +82,57 @@ cleanup_cluster()
6282
kubectl delete --recursive -f ./temp/${TESTING_TOPIC}
6383
}
6484

85+
deploy_kafka_connect_connector()
86+
{
87+
# Get MongoDB Credentials from Env Vars.
88+
89+
# Create connector payload
90+
CONNECTOR_FILE="./temp/${TESTING_TOPIC}/create-connector.json"
91+
cp ../examples/kafka_connect/connectors/mongoDBSink/CreateMongoSinkConnector.json $CONNECTOR_FILE
92+
93+
# 2 "name"
94+
KCONNECT_NAME="${TESTING_TOPIC}-connector"
95+
echo "Kafka Connect Sink Name: ${KCONNECT_NAME}"
96+
sed -i.bak "2s|.*| \"name\": \"${KCONNECT_NAME}\",|" $CONNECTOR_FILE
97+
# 4 "topic"
98+
sed -i.bak "4s|.*| \"topics\": \"${TESTING_TOPIC}\",|" $CONNECTOR_FILE
99+
# 12 "connection.uri"
100+
sed -i.bak "12s|.*| \"connection.uri\": \"${MONGODB_CONN_URL}\",|" $CONNECTOR_FILE
101+
# 13 "database"
102+
sed -i.bak "13s|.*| \"database\": \"${DATABASE}\",|" $CONNECTOR_FILE
103+
# 14 "collection"
104+
sed -i.bak "14s|.*| \"collection\": \"${COLLECTION}\",|" $CONNECTOR_FILE
105+
106+
# Portforward to kafkaconnect pod & Create Request
107+
KCONNECT_POD=`kubectl get pods -n kafka | grep kconnect-cluster-connect | awk '{print $1}'`
108+
echo "Kafka Connect Pod: ${KCONNECT_POD}"
109+
kubectl -n kafka port-forward $KCONNECT_POD 8083:8083 &
110+
KCONNECT_PORT_FORWARD_PID=$!
111+
112+
sleep 5
113+
114+
curl -H 'Content-Type: application/json' -X POST -d @$CONNECTOR_FILE http://localhost:8083/connectors
115+
116+
sleep 5
117+
kill $KCONNECT_PORT_FORWARD_PID
118+
}
119+
120+
remove_kafka_connect_connector()
121+
{
122+
# Portforward to kafkaconnect pod & Create Request
123+
KCONNECT_POD=`kubectl get pods -n kafka | grep kconnect-cluster-connect | awk '{print $1}'`
124+
echo "Kafka Connect Pod: ${KCONNECT_POD}"
125+
kubectl -n kafka port-forward $KCONNECT_POD 8083:8083 &
126+
KCONNECT_PORT_FORWARD_PID=$!
127+
128+
sleep 5
129+
130+
curl -X DELETE http://localhost:8083/connectors/$KCONNECT_NAME
131+
132+
sleep 5
133+
kill $KCONNECT_PORT_FORWARD_PID
134+
}
135+
65136
#### MAIN --------------------------------
66137

67138
# Get Broker LoadBalancer Address
@@ -92,7 +163,7 @@ kubectl apply -f temp/${TESTING_TOPIC}/kafka-test-topic.yaml
92163
sleep 2
93164

94165
# Create Kafkacat configuration based if TLS/SSL enforcement is enabled
95-
if [ $1 == "-t" ]; then
166+
if [ $MTLS_ON == true ]; then
96167
# TLS Enabled on cluster
97168
echo "${YELLOW}Configuring Kafkacat with SSL${NC}"
98169
# Deploy test user with access to test topic
@@ -119,6 +190,11 @@ if [ $1 == "-t" ]; then
119190
echo "bootstrap.servers=${BROKER_EXTERNAL_ADDRESS}" > temp/${TESTING_TOPIC}/kafkacat.config
120191
fi
121192

193+
# Deploy Kafka Connect Sink
194+
if [ $K_CONNECT_ON == true ]; then
195+
deploy_kafka_connect_connector
196+
fi
197+
122198
# Create random test messages
123199
MESSAGE_INPUT_FILE="./temp/${TESTING_TOPIC}/input-messages.txt"
124200

@@ -145,6 +221,11 @@ kill $CONSUMER_PID
145221
# Delete test topic and user
146222
cleanup_cluster $TESTING_TOPIC
147223

224+
# Deploy Kafka Connect Sink
225+
if [ $K_CONNECT_ON == true ]; then
226+
remove_kafka_connect_connector
227+
fi
228+
148229
# Compare contents of input and output
149230
SORTED_INPUT="./temp/${TESTING_TOPIC}/sorted-input.txt"
150231
SORTED_OUTPUT="./temp/${TESTING_TOPIC}/sorted-output.txt"

test/internaltest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ echo $UUID
2121
TESTING_TOPIC="topic-${UUID}"
2222
echo "${YELLOW}Test Topic: ${TESTING_TOPIC}${NC}"
2323

24+
# Create testing directory
25+
mkdir temp/${TESTING_TOPIC}
26+
2427
# TODO: Deploy via CRD with kafka-topics.yaml
2528
# Deploy via kafka broker pod - Alternatively this can be done through the CRD.
2629
kubectl exec -n kafka -ti kcluster-kafka-0 --container kafka -- bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic $TESTING_TOPIC --partitions 3 --replication-factor 2

0 commit comments

Comments
 (0)