Skip to content

Commit a8d67ad

Browse files
authored
fix: add per pod svc for orchestrator (#2377)
1 parent e2d5916 commit a8d67ad

File tree

3 files changed

+97
-42
lines changed

3 files changed

+97
-42
lines changed

addons/orchestrator/configs/orchestrator.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"RaftBind": "${ORC_POD_NAME}",
2828
"DefaultRaftPort": 10008,
2929
"RaftNodes": [ ${ORC_PEERS} ],
30+
"RaftAdvertise" : "${ORC_ADVERTISE_SVC}",
31+
"HTTPAdvertise" : "http://${ORC_ADVERTISE_SVC}:80",
3032

3133
"ApplyMySQLPromotionAfterMasterFailover": true,
3234
"DetachLostReplicasAfterMasterFailover": true,
Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,91 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
23

3-
# copy the orchestrator configuration file
4-
WORKDIR=${WORKDIR:-/opt/orchestrator}
5-
ORC_RAFT_ENABLED=${ORC_RAFT_ENABLED:-"true"}
6-
ORC_BACKEND_DB=${ORC_BACKEND_DB:-sqlite}
4+
#######################################
5+
# Signal handling
6+
#######################################
7+
ORC_PID=""
78

8-
META_MYSQL_PORT=${META_MYSQL_PORT:-3306}
9-
META_MYSQL_ENDPOINT=${META_MYSQL_ENDPOINT:-""}
10-
ORC_META_DATABASE=${ORC_META_DATABASE:-orchestrator}
9+
shutdown() {
10+
echo "Received termination signal. Shutting down orchestrator..."
11+
if [[ -n "${ORC_PID}" ]] && kill -0 "${ORC_PID}" 2>/dev/null; then
12+
kill -TERM "${ORC_PID}"
13+
wait "${ORC_PID}" || true
14+
fi
15+
}
1116

12-
mkdir -p $WORKDIR
13-
mkdir -p $WORKDIR/raft $WORKDIR/sqlite
17+
trap shutdown TERM INT EXIT
18+
19+
#######################################
20+
# Defaults & required envs
21+
#######################################
22+
WORKDIR="${WORKDIR:-/opt/orchestrator}"
23+
ORC_RAFT_ENABLED="${ORC_RAFT_ENABLED:-true}"
24+
ORC_BACKEND_DB="${ORC_BACKEND_DB:-sqlite}"
25+
26+
META_MYSQL_PORT="${META_MYSQL_PORT:-3306}"
27+
META_MYSQL_ENDPOINT="${META_MYSQL_ENDPOINT:-}"
28+
ORC_META_DATABASE="${ORC_META_DATABASE:-orchestrator}"
29+
30+
: "${CURRENT_POD_NAME:?CURRENT_POD_NAME is required}"
31+
: "${COMPONENT_NAME:?COMPONENT_NAME is required}"
32+
: "${CLUSTER_NAMESPACE:?CLUSTER_NAMESPACE is required}"
33+
: "${ORC_PER_POD_SVC:?ORC_PER_POD_SVC is required}"
34+
35+
META_MYSQL_HOST="${META_MYSQL_ENDPOINT%%:*}"
36+
37+
#######################################
38+
# Directories
39+
#######################################
40+
mkdir -p "${WORKDIR}/raft" "${WORKDIR}/sqlite"
41+
42+
#######################################
43+
# Pod / raft metadata
44+
#######################################
45+
POD_SUFFIX="${CURRENT_POD_NAME##*-}"
46+
ORC_ADVERTISE_SVC="${COMPONENT_NAME}-advertise-${POD_SUFFIX}.${CLUSTER_NAMESPACE}.svc"
47+
SUBDOMAIN="${COMPONENT_NAME}-headless.${CLUSTER_NAMESPACE}.svc"
1448

15-
SUBDOMAIN=${COMPONENT_NAME}-headless.${CLUSTER_NAMESPACE}.svc.cluster.local
16-
replicas=$(eval echo ${ORC_POD_FQDN_LIST} | tr ',' '\n')
1749
PEERS=""
18-
for replica in ${replicas}; do
19-
host=${replica}
20-
PEERS="${PEERS},\"${host}\""
50+
IFS=',' read -ra REPLICA_ARRAY <<< "${ORC_PER_POD_SVC}"
51+
for replica in "${REPLICA_ARRAY[@]}"; do
52+
host="${replica}.${CLUSTER_NAMESPACE}.svc"
53+
PEERS+=",\"${host}\""
2154
done
22-
# remove the first comma
23-
PEERS=${PEERS#,}
55+
PEERS="${PEERS#,}"
2456

25-
if [ $ORC_RAFT_ENABLED == 'true' ]; then
26-
ORC_PEERS=$PEERS
27-
ORC_POD_NAME=${CURRENT_POD_NAME}.${SUBDOMAIN}
57+
if [[ "${ORC_RAFT_ENABLED}" == "true" ]]; then
58+
ORC_PEERS="${PEERS}"
59+
ORC_POD_NAME="${CURRENT_POD_NAME}.${SUBDOMAIN}"
2860
else
2961
ORC_PEERS=""
3062
ORC_POD_NAME=""
3163
fi
3264

33-
cat /configs/orchestrator.tpl > $WORKDIR/orchestrator.conf.json
34-
# set backend db
35-
sed -i "s|\${ORC_BACKEND_DB}|${ORC_BACKEND_DB}|g" $WORKDIR/orchestrator.conf.json
36-
# set workdir
37-
sed -i "s|\${ORC_WORKDIR}|${WORKDIR}|g" $WORKDIR/orchestrator.conf.json
38-
# set orch backed db info
39-
sed -i "s/\${META_MYSQL_ENDPOINT}/${META_MYSQL_ENDPOINT%%:*}/g" $WORKDIR/orchestrator.conf.json
40-
sed -i "s/\${META_MYSQL_PORT}/$META_MYSQL_PORT/g" $WORKDIR/orchestrator.conf.json
41-
sed -i "s/\${ORC_META_DATABASE}/$ORC_META_DATABASE/g" $WORKDIR/orchestrator.conf.json
42-
43-
# set raft mode
44-
sed -i "s|\${ORC_RAFT_ENABLED}|${ORC_RAFT_ENABLED}|g" $WORKDIR/orchestrator.conf.json
65+
#######################################
66+
# Render config (single sed pass)
67+
#######################################
68+
CONFIG_FILE="${WORKDIR}/orchestrator.conf.json"
4569

46-
# set peers
47-
sed -i "s|\${ORC_PEERS}|${ORC_PEERS}|g" $WORKDIR/orchestrator.conf.json
48-
sed -i "s|\${ORC_POD_NAME}|${ORC_POD_NAME}|g" $WORKDIR/orchestrator.conf.json
70+
sed \
71+
-e "s|\${ORC_BACKEND_DB}|${ORC_BACKEND_DB}|g" \
72+
-e "s|\${ORC_WORKDIR}|${WORKDIR}|g" \
73+
-e "s|\${META_MYSQL_ENDPOINT}|${META_MYSQL_HOST}|g" \
74+
-e "s|\${META_MYSQL_PORT}|${META_MYSQL_PORT}|g" \
75+
-e "s|\${ORC_META_DATABASE}|${ORC_META_DATABASE}|g" \
76+
-e "s|\${ORC_RAFT_ENABLED}|${ORC_RAFT_ENABLED}|g" \
77+
-e "s|\${ORC_PEERS}|${ORC_PEERS}|g" \
78+
-e "s|\${ORC_POD_NAME}|${ORC_POD_NAME}|g" \
79+
-e "s|\${ORC_ADVERTISE_SVC}|${ORC_ADVERTISE_SVC}|g" \
80+
/configs/orchestrator.tpl > "${CONFIG_FILE}"
4981

50-
# set meta host
51-
sed -i "s|\${META_MYSQL_ENDPOINT}|${META_MYSQL_ENDPOINT%%:*}|g" $WORKDIR/orchestrator.conf.json
82+
#######################################
83+
# Start orchestrator
84+
#######################################
85+
/usr/local/orchestrator/orchestrator \
86+
-quiet \
87+
-config "${CONFIG_FILE}" \
88+
http &
5289

53-
/usr/local/orchestrator/orchestrator -quiet -config $WORKDIR/orchestrator.conf.json http
90+
ORC_PID=$!
91+
wait "${ORC_PID}"

addons/orchestrator/templates/cmpd-raft.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
{{- include "orchestrator.annotations" . | nindent 4 }}
99
spec:
1010
{{- include "orchestrator.cmpd.spec.common" . | nindent 2 }}
11+
podManagementPolicy: Parallel
1112
roles:
1213
- name: primary
1314
updatePriority: 2
@@ -52,12 +53,13 @@ spec:
5253
valueFrom:
5354
clusterVarRef:
5455
clusterUID: Required
55-
- name: ORC_POD_FQDN_LIST
56+
- name: ORC_PER_POD_SVC
5657
valueFrom:
57-
componentVarRef:
58-
compDef: {{ include "orchestrator.componentDefName" . }}
58+
serviceVarRef:
59+
name: advertise
5960
optional: false
60-
podFQDNs: Required
61+
host: Required
62+
6163
lifecycleActions:
6264
roleProbe:
6365
periodSeconds: {{ .Values.roleProbe.periodSeconds }}
@@ -83,6 +85,19 @@ spec:
8385
- name: orc-http
8486
port: 80
8587
targetPort: orc-http
88+
- name: advertise
89+
serviceName: advertise
90+
spec:
91+
type: ClusterIP
92+
ports:
93+
- name: orc-http
94+
port: 80
95+
targetPort: orc-http
96+
- name: raft
97+
port: 10008
98+
targetPort: raft
99+
podService: true
100+
disableAutoProvision: false
86101
runtime:
87102
containers:
88103
- name: orchestrator

0 commit comments

Comments
 (0)