From b783389ea7d651b164e7aea3d2249ee9736983bf Mon Sep 17 00:00:00 2001 From: changluyi <47097611+changluyi@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:55:33 +0800 Subject: [PATCH] refactor start-ic-db.sh (#3645) Signed-off-by: Changlu Yi --- dist/images/start-ic-db.sh | 71 +++++++++++++++---- .../templates/ic-controller-deploy.yaml | 2 +- pkg/ovn_leader_checker/ovn.go | 2 +- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/dist/images/start-ic-db.sh b/dist/images/start-ic-db.sh index 72b616c3b1f..9d86c086a8e 100755 --- a/dist/images/start-ic-db.sh +++ b/dist/images/start-ic-db.sh @@ -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') @@ -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" } @@ -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) @@ -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 @@ -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 diff --git a/kubeovn-helm/templates/ic-controller-deploy.yaml b/kubeovn-helm/templates/ic-controller-deploy.yaml index ec60974b73a..b224a0f0855 100644 --- a/kubeovn-helm/templates/ic-controller-deploy.yaml +++ b/kubeovn-helm/templates/ic-controller-deploy.yaml @@ -96,4 +96,4 @@ spec: secret: optional: true secretName: kube-ovn-tls -{{- end }} \ No newline at end of file +{{- end }} diff --git a/pkg/ovn_leader_checker/ovn.go b/pkg/ovn_leader_checker/ovn.go index b3d9f0b71e5..c4e382e8d97 100755 --- a/pkg/ovn_leader_checker/ovn.go +++ b/pkg/ovn_leader_checker/ovn.go @@ -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 }