Skip to content

Commit

Permalink
chart: fix ovs-ovn upgrade (#3613)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Jan 11, 2024
1 parent 216c929 commit fc98884
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ kind-upgrade-chart: kind-load-image
--set MASTER_NODES='$(OVN_DB_IPS)'
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
Expand Down
4 changes: 2 additions & 2 deletions charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ 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.12.4

# 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
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.12.0"
appVersion: "1.12.4"
14 changes: 14 additions & 0 deletions charts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- 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 -}}
5 changes: 4 additions & 1 deletion charts/templates/ovsovn-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +22,8 @@ spec:
app: ovs
component: network
type: infra
annotations:
chart-version: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
tolerations:
- effect: NoSchedule
Expand Down
9 changes: 5 additions & 4 deletions charts/templates/upgrade-ovs-ovn.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{ if (lookup "apps/v1" "DaemonSet" "kube-system" "ovs-ovn") }}
{{ if eq (lookup "apps/v1" "DaemonSet" "kube-system" "ovs-ovn").spec.updateStrategy.type "OnDelete" }}
{{- if eq (include "kubeovn.ovs-ovn.updateStrategy" .) "OnDelete" }}
---
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -46,6 +45,7 @@ rules:
verbs:
- list
- get
- watch
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -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:
Expand All @@ -139,4 +141,3 @@ spec:
hostPath:
path: {{ .Values.log_conf.LOG_DIR }}/kube-ovn
{{ end }}
{{ end }}
26 changes: 18 additions & 8 deletions dist/images/upgrade-ovs.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc98884

Please sign in to comment.