Skip to content

Commit 6713e13

Browse files
committed
[ovn-controller] Change startup mechanism of ovs pods
This commit aims to modify the starting scripts of the ovn-controller-ovs daemonset. This is done to allow modifying the RollingUpdate Strategy to not allow any Unavailable pod during update, what this will cause is that during an update to the pod (delete old one and create new one) instead of first deleting the first one and then deleting the next one, it will create the new pod while the old one is running. Due to how the startup scritps works currently this is not allowed. The reason behind this is to try to lower the downtime observed if the environment is using centralized floating ip during an update. With this commit the ovn-controller-ovs will share the PID namespace with the host, in order to allow signaling between old/new pod. Another change is adding an STATE that the containers (ovsdb-server, ovs-vswitchd and ovsdb-server-init) will handle internally. The differents states are: - NULL (No file): will happen the fist time ds is created on the oc worker. - INIT: First time init-ovsdb-server is executed on the oc worker. - OVSDB_SERVER: once ovsdb-server pod has run the startup script - RUNNING: Once ovsdb-server is up and ovs-vswitchd has run the startup script. - UPDATE: Once a new pod is created and ovsdb-server-init has run. - RESTART_VSWITCH: After ovsdb-server-init has finished, new ovsdb-server pod has stopped the old ovs-vswitchd process. - RESTART_DBSERVER: After old ovs-vswitchd has been restarted the old ovsdb-server is also stop. The normal flow of states is the following: NULL -> INIT -> OVSDB_SERVER -> RUNNING Scale down: If the oc worker is deleted the DS and all the pods and mount points will be deleted, in case of node being up again it should start from NULL Update: RUNNING -> (Change on CR) -> UPDATE -> RESTART_VSWITCHD -> RESTART_DBSERVER -> OVSDB_SERVER -> RUNNING Related: OSPRH-11636 Jira: OSPRH-10821
1 parent 9ef8018 commit 6713e13

File tree

11 files changed

+245
-47
lines changed

11 files changed

+245
-47
lines changed

api/go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/onsi/gomega v1.34.1
99
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62
1010
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97
11-
k8s.io/api v0.29.14
12-
k8s.io/apimachinery v0.29.14
11+
k8s.io/api v0.29.15
12+
k8s.io/apimachinery v0.29.15
1313
sigs.k8s.io/controller-runtime v0.17.6
1414
)
1515

@@ -57,9 +57,9 @@ require (
5757
gopkg.in/inf.v0 v0.9.1 // indirect
5858
gopkg.in/yaml.v2 v2.4.0 // indirect
5959
gopkg.in/yaml.v3 v3.0.1 // indirect
60-
k8s.io/apiextensions-apiserver v0.29.14 // indirect
61-
k8s.io/client-go v0.29.14 // indirect
62-
k8s.io/component-base v0.29.14 // indirect
60+
k8s.io/apiextensions-apiserver v0.29.15 // indirect
61+
k8s.io/client-go v0.29.15 // indirect
62+
k8s.io/component-base v0.29.15 // indirect
6363
k8s.io/klog/v2 v2.120.1 // indirect
6464
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
6565
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
@@ -69,3 +69,5 @@ require (
6969
)
7070

7171
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
72+
73+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 //allow-merging

api/go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 h1:UG6y5DfMsbbWDm6/ZJWWGRXrxAeNoskn4N0XVlhi8Gw=
2+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
13
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
24
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
35
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
@@ -80,8 +82,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
8082
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
8183
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62 h1:0NgCmg03wFjZEltZyHLWalTsUxOg1b7WFNlOZ4APPek=
8284
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A=
83-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
8585
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8686
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8787
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -184,16 +184,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
184184
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
185185
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
186186
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
187-
k8s.io/api v0.29.14 h1:JWFh5ufowH3Y6tCgEzY3URVJHb27f0tEDEej0nCjWDw=
188-
k8s.io/api v0.29.14/go.mod h1:IV8YqKxMm8JGLBLlHM13Npn5lCITH10XYipWEW+YEOQ=
189-
k8s.io/apiextensions-apiserver v0.29.14 h1:gw9WXrZJPu5kpI1UC+Wf8BVe9PWwRUB/UZXU8VzBsq4=
190-
k8s.io/apiextensions-apiserver v0.29.14/go.mod h1:TJ51W+HKW2XqTtAsEFOz1/OohsMtekbKaTXh8ldioL4=
191-
k8s.io/apimachinery v0.29.14 h1:IDhwnGNCp836SLOwW1SoEfFNV77wxIklhxeAHX9vmSo=
192-
k8s.io/apimachinery v0.29.14/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
193-
k8s.io/client-go v0.29.14 h1:OSnzZ9DClaFRgl3zMAY2kGZhNjdGJkEb+RDz+MW2h6k=
194-
k8s.io/client-go v0.29.14/go.mod h1:XtZt5n5UxKfPJ+sCoTPcEavWgZbLFFxMnAFFRQGK1RY=
195-
k8s.io/component-base v0.29.14 h1:SF1DWN7bc2VloJ/ysegGoi/aHnopEo81aw9CslhqXIw=
196-
k8s.io/component-base v0.29.14/go.mod h1:FoK1PHhFTaEQVvQLw29/Uyfd8Ug0qUKHrUcXIXJ1VxI=
187+
k8s.io/api v0.29.15 h1:QxPcAheYujeBwkdiE0vMyKkAtqUq5YNyXVqimT+me44=
188+
k8s.io/api v0.29.15/go.mod h1:16duIp2ez6GiLPq1g8XtZNIkw6hJpIitpxZSvv0dZ6E=
189+
k8s.io/apiextensions-apiserver v0.29.15 h1:XI5axgsWqMlIIgpHbcz5vPjk06i3ibHv5FUdSfdtQLU=
190+
k8s.io/apiextensions-apiserver v0.29.15/go.mod h1:6ZU61z32I8WUwbBTPIANUesTj5G40sZek0ojmeoMJI8=
191+
k8s.io/apimachinery v0.29.15 h1:aLc0wghElkdnTO7TMVTxTrifoXah1lqRL8s6szDHGbg=
192+
k8s.io/apimachinery v0.29.15/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
193+
k8s.io/client-go v0.29.15 h1:zCBOXKCtz9Hl8boKUGs8zbtZEP6pc7O8Ov3ma+gnS6o=
194+
k8s.io/client-go v0.29.15/go.mod h1:xPy0D3p4sonPhZhI3QoYo4m7oLKoPjFf4vYF9oxoxNM=
195+
k8s.io/component-base v0.29.15 h1:CvmXXTDyk43FDaiJ/Rp+yWFjw6hkUI2t7mIJUrK5j00=
196+
k8s.io/component-base v0.29.15/go.mod h1:jH/sbuvmXew2Fz2iIKNMeNw8o/d1KR9tAg6uekQKnVk=
197197
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
198198
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
199199
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo=

controllers/ovncontroller_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
612612
instance.Status.DesiredNumberScheduled = dset.GetDaemonSet().Status.DesiredNumberScheduled
613613
instance.Status.NumberReady = dset.GetDaemonSet().Status.NumberReady
614614

615-
// Define a new DaemonSet object for OVS (ovsdb-server + ovs-vswitchd)
616615
ovsdset := daemonset.NewDaemonSet(
617616
ovncontroller.CreateOVSDaemonSet(instance, inputHash, ovsServiceLabels, serviceAnnotations, topology),
618617
time.Duration(5)*time.Second,

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ require (
1414
github.com/openstack-k8s-operators/ovn-operator/api v0.0.0-20230418071801-b5843d9e05fb
1515
go.uber.org/zap v1.27.0
1616
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
17-
k8s.io/api v0.29.14
18-
k8s.io/apimachinery v0.29.14
19-
k8s.io/client-go v0.29.14
17+
k8s.io/api v0.29.15
18+
k8s.io/apimachinery v0.29.15
19+
k8s.io/client-go v0.29.15
2020
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
2121
sigs.k8s.io/controller-runtime v0.17.6
2222
)
@@ -69,8 +69,8 @@ require (
6969
gopkg.in/inf.v0 v0.9.1 // indirect
7070
gopkg.in/yaml.v2 v2.4.0 // indirect
7171
gopkg.in/yaml.v3 v3.0.1 // indirect
72-
k8s.io/apiextensions-apiserver v0.29.14 // indirect
73-
k8s.io/component-base v0.29.14 // indirect
72+
k8s.io/apiextensions-apiserver v0.29.15 // indirect
73+
k8s.io/component-base v0.29.15 // indirect
7474
k8s.io/klog/v2 v2.120.1 // indirect
7575
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 // indirect
7676
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
@@ -83,3 +83,5 @@ replace github.com/openstack-k8s-operators/ovn-operator/api => ./api
8383
// mschuppert: map to latest commit from release-4.16 tag
8484
// must consistent within modules and service operators
8585
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
86+
87+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 //allow-merging

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1 h1:UG6y5DfMsbbWDm6/ZJWWGRXrxAeNoskn4N0XVlhi8Gw=
2+
github.com/averdagu/lib-common/modules/common v0.0.0-20250318112303-0e4fcdf116e1/go.mod h1:1CtBP0MQffdjE6buOv5jP2rB3+h7WH0a11lcyrpmxOk=
13
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
24
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
35
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
@@ -78,8 +80,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
7880
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
7981
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62 h1:0NgCmg03wFjZEltZyHLWalTsUxOg1b7WFNlOZ4APPek=
8082
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20250301104950-9a202ca63f62/go.mod h1:JgcmYJyyMKfArK8ulZnbls0L01qt8Dq6s5LH8TZH63A=
81-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97 h1:3LC66vrXJzGMV/eCdvImosOEL2Cgc2KFJIm2YhfTG3w=
82-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:rgpcv2tLD+/vudXx/gpIQSTuRpk4GOxHx84xwfvQalM=
8383
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97 h1:2f6Fl2chkacLkElCtEtCFygtuVhEq3YuUvZbfiEBDZ8=
8484
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20250228124213-cd63da392f97/go.mod h1:oKvVb28i6wwBR5uQO2B2KMzZnCFTPCUCj31c5Zvz2lo=
8585
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -186,16 +186,16 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
186186
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
187187
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
188188
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
189-
k8s.io/api v0.29.14 h1:JWFh5ufowH3Y6tCgEzY3URVJHb27f0tEDEej0nCjWDw=
190-
k8s.io/api v0.29.14/go.mod h1:IV8YqKxMm8JGLBLlHM13Npn5lCITH10XYipWEW+YEOQ=
191-
k8s.io/apiextensions-apiserver v0.29.14 h1:gw9WXrZJPu5kpI1UC+Wf8BVe9PWwRUB/UZXU8VzBsq4=
192-
k8s.io/apiextensions-apiserver v0.29.14/go.mod h1:TJ51W+HKW2XqTtAsEFOz1/OohsMtekbKaTXh8ldioL4=
193-
k8s.io/apimachinery v0.29.14 h1:IDhwnGNCp836SLOwW1SoEfFNV77wxIklhxeAHX9vmSo=
194-
k8s.io/apimachinery v0.29.14/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
195-
k8s.io/client-go v0.29.14 h1:OSnzZ9DClaFRgl3zMAY2kGZhNjdGJkEb+RDz+MW2h6k=
196-
k8s.io/client-go v0.29.14/go.mod h1:XtZt5n5UxKfPJ+sCoTPcEavWgZbLFFxMnAFFRQGK1RY=
197-
k8s.io/component-base v0.29.14 h1:SF1DWN7bc2VloJ/ysegGoi/aHnopEo81aw9CslhqXIw=
198-
k8s.io/component-base v0.29.14/go.mod h1:FoK1PHhFTaEQVvQLw29/Uyfd8Ug0qUKHrUcXIXJ1VxI=
189+
k8s.io/api v0.29.15 h1:QxPcAheYujeBwkdiE0vMyKkAtqUq5YNyXVqimT+me44=
190+
k8s.io/api v0.29.15/go.mod h1:16duIp2ez6GiLPq1g8XtZNIkw6hJpIitpxZSvv0dZ6E=
191+
k8s.io/apiextensions-apiserver v0.29.15 h1:XI5axgsWqMlIIgpHbcz5vPjk06i3ibHv5FUdSfdtQLU=
192+
k8s.io/apiextensions-apiserver v0.29.15/go.mod h1:6ZU61z32I8WUwbBTPIANUesTj5G40sZek0ojmeoMJI8=
193+
k8s.io/apimachinery v0.29.15 h1:aLc0wghElkdnTO7TMVTxTrifoXah1lqRL8s6szDHGbg=
194+
k8s.io/apimachinery v0.29.15/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y=
195+
k8s.io/client-go v0.29.15 h1:zCBOXKCtz9Hl8boKUGs8zbtZEP6pc7O8Ov3ma+gnS6o=
196+
k8s.io/client-go v0.29.15/go.mod h1:xPy0D3p4sonPhZhI3QoYo4m7oLKoPjFf4vYF9oxoxNM=
197+
k8s.io/component-base v0.29.15 h1:CvmXXTDyk43FDaiJ/Rp+yWFjw6hkUI2t7mIJUrK5j00=
198+
k8s.io/component-base v0.29.15/go.mod h1:jH/sbuvmXew2Fz2iIKNMeNw8o/d1KR9tAg6uekQKnVk=
199199
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
200200
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
201201
k8s.io/kube-openapi v0.0.0-20240322212309-b815d8309940 h1:qVoMaQV5t62UUvHe16Q3eb2c5HPzLHYzsi0Tu/xLndo=

pkg/ovncontroller/daemonset.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
appsv1 "k8s.io/api/apps/v1"
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/util/intstr"
2728
"k8s.io/utils/ptr"
2829
)
2930

@@ -236,6 +237,27 @@ func CreateOVSDaemonSet(
236237
envVars := map[string]env.Setter{}
237238
envVars["CONFIG_HASH"] = env.SetValue(configHash)
238239

240+
volumes := []corev1.Volume{}
241+
mounts := []corev1.VolumeMount{}
242+
243+
// add OVN dbs cert and CA
244+
if instance.Spec.TLS.Enabled() {
245+
svc := tls.Service{
246+
SecretName: *instance.Spec.TLS.GenericService.SecretName,
247+
CertMount: ptr.To(ovn_common.OVNDbCertPath),
248+
KeyMount: ptr.To(ovn_common.OVNDbKeyPath),
249+
CaMount: ptr.To(ovn_common.OVNDbCaCertPath),
250+
}
251+
volumes = append(volumes, svc.CreateVolume(ovnv1.ServiceNameOVNController))
252+
mounts = append(mounts, svc.CreateVolumeMounts(ovnv1.ServiceNameOVNController)...)
253+
254+
// add CA bundle if defined
255+
if instance.Spec.TLS.CaBundleSecretName != "" {
256+
volumes = append(volumes, instance.Spec.TLS.CreateVolume())
257+
mounts = append(mounts, instance.Spec.TLS.CreateVolumeMounts(nil)...)
258+
}
259+
}
260+
239261
initContainers := []corev1.Container{
240262
{
241263
Name: "ovsdb-server-init",
@@ -250,7 +272,7 @@ func CreateOVSDaemonSet(
250272
Privileged: &privileged,
251273
},
252274
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
253-
VolumeMounts: GetOVSDbVolumeMounts(),
275+
VolumeMounts: append(GetOVSDbVolumeMounts(), mounts...),
254276
},
255277
}
256278

@@ -276,7 +298,7 @@ func CreateOVSDaemonSet(
276298
Privileged: &privileged,
277299
},
278300
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
279-
VolumeMounts: GetOVSDbVolumeMounts(),
301+
VolumeMounts: append(GetOVSDbVolumeMounts(), mounts...),
280302
// TODO: consider the fact that resources are now double booked
281303
Resources: instance.Spec.Resources,
282304
LivenessProbe: ovsDbLivenessProbe,
@@ -303,7 +325,7 @@ func CreateOVSDaemonSet(
303325
Privileged: &privileged,
304326
},
305327
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
306-
VolumeMounts: GetVswitchdVolumeMounts(),
328+
VolumeMounts: append(GetVswitchdVolumeMounts(), mounts...),
307329
// TODO: consider the fact that resources are now double booked
308330
Resources: instance.Spec.Resources,
309331
LivenessProbe: ovsVswitchdLivenessProbe,
@@ -312,6 +334,9 @@ func CreateOVSDaemonSet(
312334
},
313335
}
314336

337+
maxUnavailable := intstr.FromInt32(0)
338+
maxSurge := intstr.FromInt32(1)
339+
315340
daemonset := &appsv1.DaemonSet{
316341
ObjectMeta: metav1.ObjectMeta{
317342
Name: ovnv1.ServiceNameOVS,
@@ -327,9 +352,17 @@ func CreateOVSDaemonSet(
327352
},
328353
Spec: corev1.PodSpec{
329354
ServiceAccountName: instance.RbacResourceName(),
355+
HostPID: true,
330356
InitContainers: initContainers,
331357
Containers: containers,
332-
Volumes: GetOVSVolumes(instance.Name, instance.Namespace),
358+
Volumes: append(GetOVSVolumes(instance.Name, instance.Namespace), volumes...),
359+
},
360+
},
361+
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
362+
Type: appsv1.RollingUpdateDaemonSetStrategyType,
363+
RollingUpdate: &appsv1.RollingUpdateDaemonSet{
364+
MaxUnavailable: &maxUnavailable,
365+
MaxSurge: &maxSurge,
333366
},
334367
},
335368
},

templates/ovncontroller/bin/init-ovsdb-server.sh

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,67 @@ set -ex
1818
source $(dirname $0)/functions
1919
trap wait_for_db_creation EXIT
2020

21+
function init_ovsdb_server {
22+
# Initialize or upgrade database if needed
23+
CTL_ARGS="--system-id=random --no-ovs-vswitchd"
24+
/usr/share/openvswitch/scripts/ovs-ctl start $CTL_ARGS
25+
/usr/share/openvswitch/scripts/ovs-ctl stop $CTL_ARGS
26+
27+
if [ ! -f /var/lib/openvswitch/already_executed ]; then
28+
# If file was not present, set status INIT
29+
echo "INIT" > /var/lib/openvswitch/already_executed
30+
fi
31+
32+
wait_for_db_creation
33+
trap - EXIT
34+
}
35+
36+
TLSOptions="--certificate=/etc/pki/tls/certs/ovndb.crt --private-key=/etc/pki/tls/private/ovndb.key --ca-cert=/etc/pki/tls/certs/ovndbca.crt"
37+
DBOptions="--db ssl:ovsdbserver-nb.openstack.svc.cluster.local:6641"
38+
2139
# If db file is empty, remove it; otherwise service won't start.
2240
# See https://issues.redhat.com/browse/FDP-689 for more details.
2341
if ! [ -s ${DB_FILE} ]; then
2442
rm -f ${DB_FILE}
2543
fi
26-
# Initialize or upgrade database if needed
27-
CTL_ARGS="--system-id=random --no-ovs-vswitchd"
28-
/usr/share/openvswitch/scripts/ovs-ctl start $CTL_ARGS
29-
/usr/share/openvswitch/scripts/ovs-ctl stop $CTL_ARGS
3044

31-
wait_for_db_creation
32-
trap - EXIT
45+
# Easier debug
46+
sleep 10
47+
48+
# Check if file is created, if not means it's first execution
49+
if [ -f /var/lib/openvswitch/already_executed ]; then
50+
# Need to double check that ovsdb-server and vswitchd are actually running
51+
# (That pod was not unhealty and it got destroyed)
52+
# In the following steps we need ovsdb-server to be running, check pid file
53+
if [ ! -f /run/openvswitch/ovsdb-server.pid ]; then
54+
# No PID file, start as normal
55+
echo "No PID file found, init ovsdb_server as it's the only pod"
56+
init_ovsdb_server
57+
exit 0
58+
fi
59+
# File is created, no need to run ovs-ctl
60+
# Change state to "UPDATE"
61+
echo "UPDATE" > /var/lib/openvswitch/already_executed
62+
# Clear possible leftovers of past executions
63+
## Need to lower chassis priority
64+
# First get the system-id
65+
chassis_id=$(ovs-vsctl get Open_Vswitch . external_ids:system-id)
66+
nb_output=$(ovn-nbctl --no-leader-only $DBOptions $TLSOptions --columns=_uuid,priority find Gateway_Chassis chassis_name=$chassis_id)
67+
# Check that nbctl was executed correctly
68+
if [ $? -ne 0 ]; then
69+
echo "ERROR: ovn-nbctl find command failed"
70+
exit 1
71+
fi
72+
row_uuid=$(echo "$nb_output" | grep "_uuid" | cut -d':' -f2 | xargs)
73+
priority=$(echo "$nb_output" | grep "priority" | cut -d':' -f2 | xargs)
74+
# Save priority to be able to restore it later (It's overwritting, not appending, hence no check)
75+
echo $priority > /var/lib/openvswitch/old_priority
76+
# Set lower priority (lowest value possible 0)
77+
ovn-nbctl --no-leader-only $DBOptions $TLSOptions set Gateway_Chassis $row_uuid priority=0
78+
# Check that nbctl was executed correctly
79+
if [ $? -ne 0 ]; then
80+
echo "ERROR: ovn-nbctl set command failed"
81+
exit 1
82+
fi
83+
exit 0
84+
fi

templates/ovncontroller/bin/start-ovsdb-server.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,52 @@
1717
set -ex
1818
source $(dirname $0)/functions
1919

20+
echo "start ovsdb-server"
21+
sleep 3
22+
23+
# Check state
24+
if [ -f /var/lib/openvswitch/already_executed ]; then
25+
if [ $(cat /var/lib/openvswitch/already_executed) == "UPDATE" ]; then
26+
echo "In a middle of an upgrade"
27+
# Need to stop vswitch and dbserver
28+
# First stop vswitchd
29+
vswitchd_pid=$(cat /run/openvswitch/ovs-vswitchd.pid)
30+
# Stop vswitch
31+
echo "stopping vswitchd"
32+
bash /usr/local/bin/container-scripts/stop-vswitchd.sh
33+
echo "Done, stopped vswitchd"
34+
# Wait for vswitchd to end checking status
35+
while true; do
36+
if [ $(cat /var/lib/openvswitch/already_executed) == "RESTART_VSWITCHD" ]; then
37+
break
38+
fi
39+
sleep 0.1
40+
done
41+
echo "Status is already RESTART_VSWITCHD"
42+
bash /usr/local/bin/container-scripts/stop-ovsdb-server.sh
43+
echo "Done, stopped ovsdb-server"
44+
# vswitchd stopped
45+
# We still need to run the ovsdb-server in this new container, this can be done
46+
# with the flag --overwrite-pidfile but we need to ignore the next SIGTERM that will
47+
# send openshift, creating file to noop the stop-ovsdb-server.sh
48+
echo "setting flag to skip ovsdb-server stop"
49+
touch /var/lib/openvswitch/skip_stop_ovsdbserver
50+
else
51+
# It could happen that ovsdb-server or ovs-vwsitchd pod can't start correctly or can't get to running state
52+
# this would cause this script to be run with already_executed with an state different than "UPDATE"
53+
:
54+
fi
55+
fi
56+
2057
# Remove the obsolete semaphore file in case it still exists.
2158
cleanup_ovsdb_server_semaphore
2259

60+
# Set state to "OVSDB_SERVER"
61+
echo "OVSDB_SERVER" > /var/lib/openvswitch/already_executed
62+
2363
# Start the service
2464
ovsdb-server ${DB_FILE} \
25-
--pidfile \
65+
--pidfile --overwrite-pidfile \
2666
--remote=punix:/var/run/openvswitch/db.sock \
2767
--private-key=db:Open_vSwitch,SSL,private_key \
2868
--certificate=db:Open_vSwitch,SSL,certificate \

0 commit comments

Comments
 (0)