From 19c0d8feb49ef9461a016806c2136143741210b8 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Mon, 17 Jun 2024 05:22:42 +0000 Subject: [PATCH 1/2] 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 | 15 ++++++++++----- dist/images/upgrade-ovs.sh | 15 ++++++++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/charts/kube-ovn/templates/_helpers.tpl b/charts/kube-ovn/templates/_helpers.tpl index 1b9a0575479..1412e72a457 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 aea83910f25..c5b01d0b1dc 100755 --- a/dist/images/start-db.sh +++ b/dist/images/start-db.sh @@ -139,15 +139,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 - echo "setting ovn NB_Global option version_compatibility to ${OVN_VERSION_COMPATIBILITY}" - 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 cfde7f7e6f5..6547d3c85d7 100755 --- a/dist/images/upgrade-ovs.sh +++ b/dist/images/upgrade-ovs.sh @@ -32,11 +32,15 @@ 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/"$//'` - echo "ovn NB_Global option version_compatibility is already set to $value" + 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 fi @@ -76,4 +80,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 From 5c329325ffa483b46f571bacdcc930913368e8f3 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Mon, 17 Jun 2024 05:27:32 +0000 Subject: [PATCH 2/2] fix version comparison Signed-off-by: zhangzujian --- charts/kube-ovn/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kube-ovn/templates/_helpers.tpl b/charts/kube-ovn/templates/_helpers.tpl index 1412e72a457..646341706cf 100644 --- a/charts/kube-ovn/templates/_helpers.tpl +++ b/charts/kube-ovn/templates/_helpers.tpl @@ -67,7 +67,7 @@ Number of master nodes 22.12 {{- else if and (regexFind $versionRegex $imageVersion | semverCompare ">= 1.11.0") (regexFind $versionRegex $imageVersion | semverCompare "<= 1.11.18") -}} 22.03 - {{- else -}} + {{- else if regexFind $versionRegex $imageVersion | semverCompare "< 1.11.0" -}} 21.06 {{- end -}} {{- end -}}