Skip to content

Commit

Permalink
refactor start-ic-db.sh (#3645)
Browse files Browse the repository at this point in the history
Signed-off-by: Changlu Yi <clyi@alauda.io>
  • Loading branch information
changluyi committed Jan 22, 2024
1 parent 84c0520 commit b783389
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 17 deletions.
71 changes: 56 additions & 15 deletions dist/images/start-ic-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -eo pipefail
TS_NAME=${TS_NAME:-ts}
LOCAL_IP=${LOCAL_IP:-$POD_IP}
TS_NUM=${TS_NUM:-ts}
ENABLE_BIND_LOCAL_IP=${ENABLE_BIND_LOCAL_IP:-true}

DB_ADDR=::
if [[ $ENABLE_BIND_LOCAL_IP == "true" ]]; then
DB_ADDR="$POD_IP"
fi

function get_leader_ip {
t=$(echo -n "${NODE_IPS}" | sed 's/[[:space:]]//g' | sed 's/,/ /g')
Expand All @@ -15,9 +21,40 @@ function quit {
exit 0
}

function ovndb_query_leader {
local db=""
local db_eval=""
case $1 in
nb)
db=OVN_Northbound
db_eval="NB"
;;
sb)
db=OVN_Southbound
db_eval="SB"
;;
*)
echo "invalid database: $1"
exit 1
;;
esac

eval port="\$${db_eval}_PORT"
query='["_Server",{"table":"Database","where":[["name","==","'$db'"]],"columns":["leader"],"op":"select"}]'
if [[ "$ENABLE_SSL" == "false" ]]; then
timeout 10 ovsdb-client query $(gen_conn_addr $i $port) "$query"
else
timeout 10 ovsdb-client -p /var/run/tls/key -c /var/run/tls/cert -C /var/run/tls/cacert query $(gen_conn_addr $i $port) "$query"
fi
}

function gen_conn_str {
t=$(echo -n "${NODE_IPS}" | sed 's/[[:space:]]//g' | sed 's/,/ /g')
x=$(for i in ${t}; do echo -n "tcp:[$i]:$1",; done| sed 's/,$//')
if [[ "$ENABLE_SSL" == "false" ]]; then
x=$(for i in ${t}; do echo -n "tcp:[$i]:$1",; done| sed 's/,$//')
else
x=$(for i in ${t}; do echo -n "ssl:[$i]:$1",; done| sed 's/,$//')
fi
echo "$x"
}

Expand Down Expand Up @@ -112,7 +149,7 @@ ovn_db_pre_start ic_nb
ovn_db_pre_start ic_sb

if [[ -z "$NODE_IPS" && -z "$LOCAL_IP" ]]; then
/usr/share/ovn/scripts/ovn-ctl --db-ic-nb-create-insecure-remote=yes --db-ic-sb-create-insecure-remote=yes start_ic_ovsdb
/usr/share/ovn/scripts/ovn-ctl --db-ic-nb-create-insecure-remote=yes --db-ic-sb-create-insecure-remote=yes --db-ic-nb-addr="[::]" --db-ic-sb-addr="[::]" start_ic_ovsdb
/usr/share/ovn/scripts/ovn-ctl status_ic_ovsdb
else
ic_nb_leader_ip=$(get_leader_ip nb)
Expand All @@ -126,32 +163,34 @@ else
echo "leader start with local ${LOCAL_IP} and cluster $(gen_conn_str 6647)"
/usr/share/ovn/scripts/ovn-ctl --db-ic-nb-create-insecure-remote=yes \
--db-ic-sb-create-insecure-remote=yes \
--db-ic-sb-cluster-local-addr="${LOCAL_IP}" \
--db-ic-nb-cluster-local-addr="${LOCAL_IP}" \
--db-ic-sb-cluster-local-addr="[${LOCAL_IP}]" \
--db-ic-nb-cluster-local-addr="[${LOCAL_IP}]" \
--ovn-ic-nb-db="$(gen_conn_str 6647)" \
--ovn-ic-sb-db="$(gen_conn_str 6648)" \
--db-ic-nb-addr=[$DB_ADDR] \
--db-ic-sb-addr=[$DB_ADDR] \
start_ic_ovsdb
/usr/share/ovn/scripts/ovn-ctl status_ic_ovsdb
else
# known leader always first
# known leader always first
set +eo pipefail
if [ ${result} -eq 0 ]; then
t=$(echo -n "${NODE_IPS}" | sed 's/,/ /g')
for i in ${t};
do
ic_nb_leader=$(timeout 10 ovsdb-client query "tcp:${i}:6645" "[\"_Server\",{\"table\":\"Database\",\"where\":[[\"name\",\"==\", \"OVN_IC_Northbound\"]],\"columns\": [\"leader\"],\"op\":\"select\"}]")
if [[ $ic_nb_leader =~ "true" ]]
nb_leader=$(ovndb_query_leader nb $i)
if [[ $nb_leader =~ "true" ]]
then
ic_nb_leader_ip=${i}
nb_leader_ip=${i}
break
fi
done
for i in ${t};
do
ic_sb_leader=$(timeout 10 ovsdb-client query "tcp:${i}:6646" "[\"_Server\",{\"table\":\"Database\",\"where\":[[\"name\",\"==\", \"OVN_IC_Southbound\"]],\"columns\": [\"leader\"],\"op\":\"select\"}]")
if [[ $ic_sb_leader =~ "true" ]]
sb_leader=$(ovndb_query_leader sb $i)
if [[ $sb_leader =~ "true" ]]
then
ic_sb_leader_ip=${i}
sb_leader_ip=${i}
break
fi
done
Expand All @@ -160,12 +199,14 @@ else
echo "follower start with local ${LOCAL_IP}, ovn-ic-nb leader ${ic_nb_leader_ip} ovn-ic-sb leader ${ic_sb_leader_ip}"
/usr/share/ovn/scripts/ovn-ctl --db-ic-nb-create-insecure-remote=yes \
--db-ic-sb-create-insecure-remote=yes \
--db-ic-sb-cluster-local-addr="${LOCAL_IP}" \
--db-ic-nb-cluster-local-addr="${LOCAL_IP}" \
--db-ic-nb-cluster-remote-addr="${ic_nb_leader_ip}" \
--db-ic-sb-cluster-remote-addr="${ic_sb_leader_ip}" \
--db-ic-sb-cluster-local-addr="[${LOCAL_IP}]" \
--db-ic-nb-cluster-local-addr="[${LOCAL_IP}]" \
--db-ic-nb-cluster-remote-addr="[${ic_nb_leader_ip}]" \
--db-ic-sb-cluster-remote-addr="[${ic_sb_leader_ip}]" \
--ovn-ic-nb-db="$(gen_conn_str 6647)" \
--ovn-ic-sb-db="$(gen_conn_str 6648)" \
--db-ic-nb-addr=[$DB_ADDR] \
--db-ic-sb-addr=[$DB_ADDR] \
start_ic_ovsdb
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion kubeovn-helm/templates/ic-controller-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ spec:
secret:
optional: true
secretName: kube-ovn-tls
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion pkg/ovn_leader_checker/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func updateTS() error {
return fmt.Errorf("expectTSCount atoi failed output: %s, err: %v", output, err)
}
if expectTSCount == existTSCount {
klog.Info("%d TS found, no chenges required.")
klog.V(3).Infof("expectTSCount %d no changes required.", expectTSCount)
return nil
}

Expand Down

0 comments on commit b783389

Please sign in to comment.