diff --git a/Makefile b/Makefile index 40a06026f68..26463f9987c 100644 --- a/Makefile +++ b/Makefile @@ -484,7 +484,7 @@ kind-upgrade-chart: kind-load-image --set global.images.kubeovn.tag=$(VERSION) sleep 90 kubectl -n kube-system rollout status --timeout=1s deployment/ovn-central - kubectl -n kube-system rollout status --timeout=1s daemonset/ovs-ovn + kubectl -n kube-system wait pod --for=condition=ready -l app=ovs kubectl -n kube-system rollout status --timeout=1s deployment/kube-ovn-controller kubectl -n kube-system rollout status --timeout=1s daemonset/kube-ovn-cni kubectl -n kube-system rollout status --timeout=1s daemonset/kube-ovn-pinger diff --git a/charts/Chart.yaml b/charts/Chart.yaml index 1cb8212f346..fce1b22070a 100644 --- a/charts/Chart.yaml +++ b/charts/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 +version: 1.13.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl index 8be2462daef..60f68fdc203 100644 --- a/charts/templates/_helpers.tpl +++ b/charts/templates/_helpers.tpl @@ -29,3 +29,18 @@ Number of master nodes {{- define "kubeovn.nodeCount" -}} {{- len (split "," (.Values.MASTER_NODES | default (include "kubeovn.nodeIPs" .))) }} {{- end -}} + +{{- define "kubeovn.ovs-ovn.updateStrategy" -}} + {{- $ds := lookup "apps/v1" "DaemonSet" $.Values.namespace "ovs-ovn" -}} + {{- if $ds -}} + {{- $updateStrategy := $ds.spec.updateStrategy.type }} + {{- $imageVersion := index ((index $ds.spec.template.spec.containers 0).image | splitList ":") 1 | trimPrefix "v" }} + {{- if or (eq $updateStrategy "RollingUpdate") (semverCompare ">= 1.12.0" $imageVersion) -}} + RollingUpdate + {{- else -}} + OnDelete + {{- end -}} + {{- else -}} + RollingUpdate + {{- end -}} +{{- end -}} diff --git a/charts/crds/crd.yaml b/charts/templates/kube-ovn-crd.yaml similarity index 100% rename from charts/crds/crd.yaml rename to charts/templates/kube-ovn-crd.yaml diff --git a/charts/templates/ovsovn-ds.yaml b/charts/templates/ovsovn-ds.yaml index 319d74a98d0..f870e1f52cd 100644 --- a/charts/templates/ovsovn-ds.yaml +++ b/charts/templates/ovsovn-ds.yaml @@ -6,12 +6,13 @@ metadata: annotations: kubernetes.io/description: | This daemon set launches the openvswitch daemon. + chart-version: "{{ .Chart.Name }}-{{ .Chart.Version }}" spec: selector: matchLabels: app: ovs updateStrategy: - type: RollingUpdate + type: {{ include "kubeovn.ovs-ovn.updateStrategy" . }} rollingUpdate: maxSurge: 1 maxUnavailable: 0 @@ -21,6 +22,8 @@ spec: app: ovs component: network type: infra + annotations: + chart-version: "{{ .Chart.Name }}-{{ .Chart.Version }}" spec: tolerations: - effect: NoSchedule diff --git a/charts/templates/upgrade-ovs-ovn.yaml b/charts/templates/upgrade-ovs-ovn.yaml index 980354e6bd0..67118133086 100644 --- a/charts/templates/upgrade-ovs-ovn.yaml +++ b/charts/templates/upgrade-ovs-ovn.yaml @@ -1,5 +1,4 @@ -{{ if (lookup "apps/v1" "DaemonSet" .Values.namespace "ovs-ovn") }} -{{ if eq (lookup "apps/v1" "DaemonSet" .Values.namespace "ovs-ovn").spec.updateStrategy.type "OnDelete" }} +{{- if eq (include "kubeovn.ovs-ovn.updateStrategy" .) "OnDelete" }} --- apiVersion: v1 kind: ServiceAccount @@ -46,6 +45,7 @@ rules: verbs: - list - get + - watch - delete --- apiVersion: rbac.authorization.k8s.io/v1 @@ -128,7 +128,9 @@ spec: fieldRef: fieldPath: metadata.namespace command: - - sh + - bash + - -eo + - pipefail - -c - /kube-ovn/upgrade-ovs.sh 2>&1 | tee -a /var/log/kube-ovn/upgrade-ovs.log volumeMounts: @@ -139,4 +141,3 @@ spec: hostPath: path: {{ .Values.log_conf.LOG_DIR }}/kube-ovn {{ end }} -{{ end }} diff --git a/dist/images/upgrade-ovs.sh b/dist/images/upgrade-ovs.sh index 6ecabecae9b..ca49f554ce5 100755 --- a/dist/images/upgrade-ovs.sh +++ b/dist/images/upgrade-ovs.sh @@ -1,20 +1,30 @@ #!/bin/bash -set -e +set -ex POD_NAMESPACE=${POD_NAMESPACE:-kube-system} -dsGenVer=`kubectl -n $POD_NAMESPACE get ds ovs-ovn -o jsonpath={.metadata.generation}` -kubectl -n $POD_NAMESPACE delete pod -l app=ovs,pod-template-generation!=$dsGenVer +dsChartVer=`kubectl get ds -n $POD_NAMESPACE ovs-ovn -o jsonpath={.spec.template.metadata.annotations.chart-version}` for node in `kubectl get node -o jsonpath='{.items[*].metadata.name}'`; do - # wait the pod with new version to be created and delete it + pods=(`kubectl -n $POD_NAMESPACE get pod -l app=ovs --field-selector spec.nodeName=$node -o name`) + for pod in ${pods[*]}; do + podChartVer=`kubectl -n $POD_NAMESPACE get $pod -o jsonpath={.metadata.annotations.chart-version}` + if [ "$dsChartVer" != "$podChartVer" ]; then + echo "deleting $pod on node $node" + kubectl -n $POD_NAMESPACE delete $pod + fi + done + while true; do - pod=`kubectl -n $POD_NAMESPACE get pod -l app=ovs,pod-template-generation=$dsGenVer --field-selector spec.nodeName=$node -o name` - if [ ! -z $pod ]; then - kubectl -n $POD_NAMESPACE delete $pod --wait=false + pods=(`kubectl -n $POD_NAMESPACE get pod -l app=ovs --field-selector spec.nodeName=$node -o name`) + if [ ${#pods[*]} -ne 0 ]; then break fi - sleep 0.1 + echo "waiting for ovs-ovn pod on node $node to be created" + sleep 1 done + + echo "waiting for ovs-ovn pod on node $node to be ready" + kubectl -n $POD_NAMESPACE wait pod --for=condition=ready -l app=ovs --field-selector spec.nodeName=$node done