From bdcee031b432c8e0de5632243e7cf409ebd0fcd3 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Mon, 17 Jun 2024 05:22:42 +0000 Subject: [PATCH] use ovn-controller option external_ids:ovn-match-northd-version to improve upgrade process Signed-off-by: zhangzujian --- charts/kube-ovn/templates/_helpers.tpl | 6 ++---- dist/images/start-db.sh | 14 ++++++++++---- dist/images/upgrade-ovs.sh | 13 +++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/charts/kube-ovn/templates/_helpers.tpl b/charts/kube-ovn/templates/_helpers.tpl index 18b5c5440c94..2cdaf254d656 100644 --- a/charts/kube-ovn/templates/_helpers.tpl +++ b/charts/kube-ovn/templates/_helpers.tpl @@ -63,11 +63,9 @@ Number of master nodes {{- $imageVersion := (index $ds.spec.template.spec.containers 0).image | splitList ":" | last | trimPrefix "v" -}} {{- $versionRegex := `^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)` -}} {{- if and (ne $newChartVersion $chartVersion) (regexMatch $versionRegex $imageVersion) -}} - {{- if regexFind $versionRegex $imageVersion | semverCompare ">= 1.13.0" -}} - 24.03 - {{- else if regexFind $versionRegex $imageVersion | semverCompare ">= 1.12.0" -}} + {{- if and (regexFind $versionRegex $imageVersion | semverCompare ">= 1.12.0") (regexFind $versionRegex $imageVersion | semverCompare "<= 1.12.17") -}} 22.12 - {{- else if regexFind $versionRegex $imageVersion | semverCompare ">= 1.11.0" -}} + {{- else if and (regexFind $versionRegex $imageVersion | semverCompare ">= 1.11.0") (regexFind $versionRegex $imageVersion | semverCompare "<= 1.11.18") -}} 22.03 {{- else -}} 21.06 diff --git a/dist/images/start-db.sh b/dist/images/start-db.sh index c160f1832528..f05f21303613 100755 --- a/dist/images/start-db.sh +++ b/dist/images/start-db.sh @@ -138,14 +138,20 @@ function is_clustered { function set_nb_version_compatibility() { if [ -n "$OVN_VERSION_COMPATIBILITY" ]; then - if ! ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS get NB_Global . options | grep -q version_compatibility=; then - ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS set NB_Global . options:version_compatibility=${OVN_VERSION_COMPATIBILITY} + alias _nbctl="ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS" + if ! _nbctl get NB_Global . external-ids | grep -w 'ovn-match-northd-version="true"'; then + # Do not set version_compatibility. Use ovn-controller external-ids:ovn-match-northd-version=true instead. return fi - value=`ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS get NB_Global . options:version_compatibility | sed -e 's/^"//' -e 's/"$//'` + + if ! _nbctl get NB_Global . options | grep -q version_compatibility=; then + _nbctl set NB_Global . options:version_compatibility=${OVN_VERSION_COMPATIBILITY} + return + fi + value=`_nbctl get NB_Global . options:version_compatibility | sed -e 's/^"//' -e 's/"$//'` echo "ovn nb global option version_compatibility is set to $value" if [ "$value" != "_$OVN_VERSION_COMPATIBILITY" ]; then - ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS set NB_Global . options:version_compatibility=${OVN_VERSION_COMPATIBILITY} + _nbctl set NB_Global . options:version_compatibility=${OVN_VERSION_COMPATIBILITY} fi fi } diff --git a/dist/images/upgrade-ovs.sh b/dist/images/upgrade-ovs.sh index 33232bc755cc..94283e44ad52 100755 --- a/dist/images/upgrade-ovs.sh +++ b/dist/images/upgrade-ovs.sh @@ -34,10 +34,14 @@ function gen_conn_str { echo "$x" } -nb_addr="$(gen_conn_str 6641)" +alias _nbctl="ovn-nbctl --db=$(gen_conn_str 6641) $SSL_OPTIONS" +if ! _nbctl get NB_Global . external-ids | grep -w 'ovn-match-northd-version="true"'; then + exit +fi + while true; do - if [ x`ovn-nbctl --db=$nb_addr $SSL_OPTIONS get NB_Global . options | grep -o 'version_compatibility='` != "x" ]; then - value=`ovn-nbctl --db=$nb_addr $SSL_OPTIONS get NB_Global . options:version_compatibility | sed -e 's/^"//' -e 's/"$//'` + if [ x`_nbctl get NB_Global . options | grep -o 'version_compatibility='` != "x" ]; then + value=`_nbctl get NB_Global . options:version_compatibility | sed -e 's/^"//' -e 's/"$//'` echo "ovn NB_Global option version_compatibility is set to $value" if [ "$value" = "$OVN_VERSION_COMPATIBILITY" -o "$value" = "_$OVN_VERSION_COMPATIBILITY" ]; then break @@ -78,4 +82,5 @@ else kubectl -n $POD_NAMESPACE rollout status ds/ovs-ovn fi -ovn-nbctl --db=$nb_addr $SSL_OPTIONS set NB_Global . options:version_compatibility=_$OVN_VERSION_COMPATIBILITY +_nbctl set NB_Global . external-ids:ovn-match-northd-version=true +_nbctl remove NB_Global . options version_compatibility