Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG TARGETOS
ARG TARGETARCH

# Install necessary dependencies
RUN apk add --no-cache
RUN apk add --no-cache curl jq
COPY init-scripts /init-scripts
COPY scripts /tmp/scripts

Expand Down
23 changes: 21 additions & 2 deletions init-scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ set -o pipefail
# set -o xtrace # Uncomment this line for debugging purposes

cp -r /tmp/scripts/* /opt/kafka/init-scripts

# TODO(): kafka rack id extraction from pod scheduled node using label
if [[ -n "${TOPOLOGY_KEY:-}" && -n "${NODE_NAME:-}" ]]; then
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
APISERVER="https://kubernetes.default.svc"
CACERT="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
RESPONSE=$(curl -s --cacert $CACERT --header "Authorization: Bearer $TOKEN" \
--header "Accept: application/json" \
$APISERVER/api/v1/nodes/$NODE_NAME)
if [ $? -ne 0 ]; then
echo "Error: Failed to query API server" >&2
exit 1
fi
echo $RESPONSE
LABEL_VALUE=$(echo $RESPONSE | jq -r ".metadata.labels.\"$TOPOLOGY_KEY\" // error(\"Label $TOPOLOGY_KEY not found\")")
# if error returned from here, exit
if [ $? -ne 0 ]; then
echo "Error: Label $TOPOLOGY_KEY not found on node $NODE_NAME" >&2
exit 1
fi
echo "broker.rack=$LABEL_VALUE" >> /opt/kafka/init-scripts/rack.properties
echo "Set broker.rack=$LABEL_VALUE for node $NODE_NAME"
fi

echo "Kafka Initializing Done!!"
10 changes: 10 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ update_configuration() {
cat "$operator_config" "$server_config" | awk -F'=' '!seen[$1]++' > "$server_config.updated"
mv "$server_config.updated" "$final_config_path"
fi
# If $process_roles is not controller and /opt/kafka/init-scripts/rack.properties file exists,
# append or replace rack.id in final_config_path
if [[ "$process_roles" != "controller" && -f /opt/kafka/init-scripts/rack.properties ]]; then
if grep -q "^broker.rack=" "$final_config_path"; then
sed -i "s/^broker.rack=.*/$(grep '^broker.rack=' /opt/kafka/init-scripts/rack.properties)/" "$final_config_path"
else
cat /opt/kafka/init-scripts/rack.properties >> "$final_config_path"
fi
fi

info "Updated configuration file by process_roles"
}

Expand Down