Skip to content

Commit

Permalink
Add support to run custom scripts (Fix merge conflict with the latest…
Browse files Browse the repository at this point in the history
… master) (confluentinc#392)

Thank you @amit-k-yadav
  • Loading branch information
amit-k-yadav authored Apr 2, 2020
1 parent 6d5fd5b commit bc75a82
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions charts/cp-kafka-connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ The configuration parameters in this section control the resources requested and
| `prometheus.jmx.port` | JMX Exporter Port which exposes metrics in Prometheus format for scraping. | `5556` |
| `prometheus.jmx.resources` | JMX Exporter resources configuration. | see [values.yaml](values.yaml) for details |

### Running Custom Scripts

| Parameter | Description | Default |
| --------- | ----------- | ------- |
| `customEnv.CUSTOM_SCRIPT_PATH` | Path to external bash script to run inside the container | see [values.yaml](values.yaml) for details |
| `livenessProbe` | Requirement of `livenessProbe` depends on the custom script to be run | see [values.yaml](values.yaml) for details |

### Deployment Topology

| Parameter | Description | Default |
Expand Down
13 changes: 13 additions & 0 deletions charts/cp-kafka-connect/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ spec:
- name: KAFKA_JMX_PORT
value: "{{ .Values.jmx.port }}"
{{- end }}
{{- if .Values.customEnv.CUSTOM_SCRIPT_PATH }}
command:
- /bin/bash
- -c
- |
/etc/confluent/docker/run &
$CUSTOM_SCRIPT_PATH
sleep infinity
{{- if .Values.livenessProbe }}
livenessProbe:
{{ toYaml .Values.livenessProbe | trim | indent 12 }}
{{- end }}
{{- end }}
{{- if .Values.volumeMounts }}
volumeMounts:
{{ toYaml .Values.volumeMounts | indent 10 }}
Expand Down
15 changes: 15 additions & 0 deletions charts/cp-kafka-connect/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ configurationOverrides:
heapOptions: "-Xms512M -Xmx512M"

## Additional env variables
## CUSTOM_SCRIPT_PATH is the path of the custom shell script to be ran mounted in a volume
customEnv: {}
# CUSTOM_SCRIPT_PATH: /etc/scripts/create-connectors.sh

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down Expand Up @@ -114,3 +116,16 @@ volumes:
secrets:
# username: kafka123
# password: connect321

## These values are used only when "customEnv.CUSTOM_SCRIPT_PATH" is defined.
## "livenessProbe" is required only for the edge cases where the custom script to be ran takes too much time
## and errors by the ENTRYPOINT are ignored by the container
## As an example such a similar script is added to "cp-helm-charts/examples/create-connectors.sh"
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
# httpGet:
# path: /connectors
# port: 8083
# initialDelaySeconds: 30
# periodSeconds: 5
# failureThreshold: 10
31 changes: 31 additions & 0 deletions examples/create-connectors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## A script similar to this can be used to create connectors making sure the endpoints are ready

echo "Waiting for Kafka Connect to start listening on kafka-connect "
while :; do
# Check if the connector endpoint is ready
# If not check again
curl_status=$(curl -s -o /dev/null -w %{http_code} http://localhost:{{ .Values.servicePort }}/connectors)
echo -e $(date) "Kafka Connect listener HTTP state: " $curl_status " (waiting for 200)"
if [ $curl_status -eq 200 ]; then
break
fi
sleep 5
done

echo "======> Creating connectors"
# Send a simple POST request to create the connector
curl -X POST \
-H "Content-Type: application/json" \
--data '{
"name": "sample-connector",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
"tasks.max": 1,
"connection.url": "jdbc:mysql://123.4.5.67:3306/test_db?user=root&password=pass",
"mode": "incrementing",
"incrementing.column.name": "id",
"timestamp.column.name": "modified",
"topic.prefix": "sample-connector-",
"poll.interval.ms": 1000
}
}' http://$CONNECT_REST_ADVERTISED_HOST_NAME:8083/connectors

0 comments on commit bc75a82

Please sign in to comment.