From c9244435c23f5a152e2c4a8c8f1526f27f65dd5f Mon Sep 17 00:00:00 2001 From: Arnau Verdaguer Date: Fri, 13 Sep 2024 10:14:38 +0200 Subject: [PATCH] [ovn-controller] Don't create ovn-controller if nicMappings empty If nicMappings is empty on the ovn/ovn-controller section don't spawn the ovn-controller as it won't do anything. Resolves: OSPRH-7463 --- .../core_v1beta1_openstackcontrolplane.yaml | 2 +- pkg/openstack/ovn.go | 4 +-- .../openstackoperator_controller_test.go | 36 +++++++++++++++++++ .../openstackversion_controller_test.go | 5 +++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/config/samples/base/openstackcontrolplane/core_v1beta1_openstackcontrolplane.yaml b/config/samples/base/openstackcontrolplane/core_v1beta1_openstackcontrolplane.yaml index f2e59375d..d738a67a1 100644 --- a/config/samples/base/openstackcontrolplane/core_v1beta1_openstackcontrolplane.yaml +++ b/config/samples/base/openstackcontrolplane/core_v1beta1_openstackcontrolplane.yaml @@ -97,9 +97,9 @@ spec: replicas: 1 dbType: SB storageRequest: 10G + ovnController: {} ovnNorthd: replicas: 1 - ovnController: {} neutron: template: databaseInstance: openstack diff --git a/pkg/openstack/ovn.go b/pkg/openstack/ovn.go index 77c5fc279..e0a0b68aa 100644 --- a/pkg/openstack/ovn.go +++ b/pkg/openstack/ovn.go @@ -59,7 +59,7 @@ func ReconcileOVN(ctx context.Context, instance *corev1beta1.OpenStackControlPla if OVNDBClustersReady && OVNNorthdReady && OVNControllerReady { Log.Info("OVN is ready") instance.Status.Conditions.MarkTrue(corev1beta1.OpenStackControlPlaneOVNReadyCondition, corev1beta1.OpenStackControlPlaneOVNReadyMessage) - } else if !instance.Spec.Ovn.Enabled { + } else if !instance.Spec.Ovn.Enabled || len(instance.Spec.Ovn.Template.OVNController.NicMappings) == 0 { instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneOVNReadyCondition) } else { instance.Status.Conditions.Set(condition.FalseCondition( @@ -307,7 +307,7 @@ func ReconcileOVNController(ctx context.Context, instance *corev1beta1.OpenStack }, } - if !instance.Spec.Ovn.Enabled { + if !instance.Spec.Ovn.Enabled || len(instance.Spec.Ovn.Template.OVNController.NicMappings) == 0 { instance.Status.ContainerImages.OvnControllerImage = nil instance.Status.ContainerImages.OvnControllerOvsImage = nil if _, err := EnsureDeleted(ctx, helper, OVNController); err != nil { diff --git a/tests/functional/ctlplane/openstackoperator_controller_test.go b/tests/functional/ctlplane/openstackoperator_controller_test.go index 56c8d779c..35257c081 100644 --- a/tests/functional/ctlplane/openstackoperator_controller_test.go +++ b/tests/functional/ctlplane/openstackoperator_controller_test.go @@ -1620,6 +1620,11 @@ var _ = Describe("OpenStackOperator controller", func() { "dbType": "SB", }, }, + "ovnController": map[string]interface{}{ + "nicMappings": map[string]interface{}{ + "datacentre": "ospbr", + }, + }, }, } DeferCleanup( @@ -1670,6 +1675,37 @@ var _ = Describe("OpenStackOperator controller", func() { }, timeout, interval).Should(Succeed()) }) + It("should remove ovn-controller if nicMappings are removed", func() { + // Update spec + Eventually(func(g Gomega) { + OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName) + OSCtlplane.Spec.Ovn.Template.OVNController.NicMappings = nil + g.Expect(k8sClient.Update(ctx, OSCtlplane)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + // ovn services exist + Eventually(func(g Gomega) { + ovnNorthd := ovn.GetOVNNorthd(names.OVNNorthdName) + g.Expect(ovnNorthd).Should(Not(BeNil())) + }, timeout, interval).Should(Succeed()) + + // If nicMappings are not configured, ovnController shouldn't spawn + Eventually(func(g Gomega) { + instance := &ovnv1.OVNController{} + g.Expect(th.K8sClient.Get(th.Ctx, names.OVNControllerName, instance)).Should(Not(Succeed())) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + ovnDbServerNB := ovn.GetOVNDBCluster(names.OVNDbServerNBName) + g.Expect(ovnDbServerNB).Should(Not(BeNil())) + }, timeout, interval).Should(Succeed()) + + Eventually(func(g Gomega) { + ovnDbServerSB := ovn.GetOVNDBCluster(names.OVNDbServerSBName) + g.Expect(ovnDbServerSB).Should(Not(BeNil())) + }, timeout, interval).Should(Succeed()) + }) + It("should remove OVN resources on disable", func() { Eventually(func(g Gomega) { OSCtlplane := GetOpenStackControlPlane(names.OpenStackControlplaneName) diff --git a/tests/functional/ctlplane/openstackversion_controller_test.go b/tests/functional/ctlplane/openstackversion_controller_test.go index f5deccd39..be12b613f 100644 --- a/tests/functional/ctlplane/openstackversion_controller_test.go +++ b/tests/functional/ctlplane/openstackversion_controller_test.go @@ -237,6 +237,11 @@ var _ = Describe("OpenStackOperator controller", func() { "dbType": "SB", }, }, + "ovnController": map[string]interface{}{ + "nicMappings": map[string]interface{}{ + "datacentre": "ospbr", + }, + }, }, } DeferCleanup(