Skip to content

Commit

Permalink
[ovn-controller] Don't create ovn-controller if nicMappings empty
Browse files Browse the repository at this point in the history
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
  • Loading branch information
averdagu committed Sep 17, 2024
1 parent 749d164 commit c924443
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ spec:
replicas: 1
dbType: SB
storageRequest: 10G
ovnController: {}
ovnNorthd:
replicas: 1
ovnController: {}
neutron:
template:
databaseInstance: openstack
Expand Down
4 changes: 2 additions & 2 deletions pkg/openstack/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions tests/functional/ctlplane/openstackoperator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,11 @@ var _ = Describe("OpenStackOperator controller", func() {
"dbType": "SB",
},
},
"ovnController": map[string]interface{}{
"nicMappings": map[string]interface{}{
"datacentre": "ospbr",
},
},
},
}
DeferCleanup(
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/ctlplane/openstackversion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ var _ = Describe("OpenStackOperator controller", func() {
"dbType": "SB",
},
},
"ovnController": map[string]interface{}{
"nicMappings": map[string]interface{}{
"datacentre": "ospbr",
},
},
},
}
DeferCleanup(
Expand Down

0 comments on commit c924443

Please sign in to comment.