Skip to content

Commit cc27bc1

Browse files
committed
Sets all labels at the end of the init script,
to speed up a bit and reduce the risk that it interferes with actual config. Also if the init script goes crash looping you won't get warnings about labels already being set.
1 parent f76e192 commit cc27bc1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

kafka/10broker-config.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ data:
1111
KAFKA_BROKER_ID=${HOSTNAME##*-}
1212
sed -i "s/#init#broker.id=#init#/broker.id=$KAFKA_BROKER_ID/" /etc/kafka/server.properties
1313
14+
LABELS="kafka-broker-id=$KAFKA_BROKER_ID"
15+
1416
hash kubectl 2>/dev/null || {
1517
sed -i "s/#init#broker.rack=#init#/#init#broker.rack=# kubectl not found in path/" /etc/kafka/server.properties
1618
} && {
@@ -21,19 +23,20 @@ data:
2123
sed -i "s/#init#broker.rack=#init#/#init#broker.rack=# zone label not found for node $NODE_NAME/" /etc/kafka/server.properties
2224
else
2325
sed -i "s/#init#broker.rack=#init#/broker.rack=$ZONE/" /etc/kafka/server.properties
24-
kubectl -n $POD_NAMESPACE label pod $POD_NAME kafka-broker-rack=$ZONE
26+
LABELS="$LABELS kafka-broker-rack=$ZONE"
2527
fi
2628
27-
kubectl -n $POD_NAMESPACE label pod $POD_NAME kafka-broker-id=$KAFKA_BROKER_ID
28-
2929
OUTSIDE_HOST=$(kubectl get node "$NODE_NAME" -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}')
3030
if [ $? -ne 0 ]; then
3131
echo "Outside (i.e. cluster-external access) host lookup command failed"
3232
else
3333
OUTSIDE_PORT=3240${KAFKA_BROKER_ID}
3434
sed -i "s|#init#advertised.listeners=OUTSIDE://#init#|advertised.listeners=OUTSIDE://${OUTSIDE_HOST}:${OUTSIDE_PORT}|" /etc/kafka/server.properties
35-
kubectl -n $POD_NAMESPACE label pod $POD_NAME kafka-listener-outside-host=$OUTSIDE_HOST
36-
kubectl -n $POD_NAMESPACE label pod $POD_NAME kafka-listener-outside-port=$OUTSIDE_PORT
35+
LABELS="$LABELS kafka-listener-outside-host=$OUTSIDE_HOST kafka-listener-outside-port=$OUTSIDE_PORT"
36+
fi
37+
38+
if [ ! -z "$LABELS" ]; then
39+
kubectl -n $POD_NAMESPACE label pod $POD_NAME $LABELS || echo "Failed to label $POD_NAMESPACE.$POD_NAME - RBAC issue?"
3740
fi
3841
}
3942

rbac-namespace-default/pod-labler.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# $ kubectl -n kafka logs kafka-2 -c init-config
44
# ...
5-
# + kubectl -n kafka label pod kafka-2 kafka-broker-id=2
65
# Error from server (Forbidden): pods "kafka-2" is forbidden: User "system:serviceaccount:kafka:default" cannot get pods in the namespace "kafka": Unknown user "system:serviceaccount:kafka:default"
76
#
87
---

0 commit comments

Comments
 (0)