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 20, 2024
1 parent 749d164 commit d68c339
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 1 deletion.
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
17 changes: 17 additions & 0 deletions config/samples/nad_datacentre.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
annotations:
labels:
osp/net: data-centre
service: ovn-controller
name: datacentre
spec:
config: |
{
"cniVersion": "0.3.1",
"name": "datacentre",
"type": "bridge",
"bridge": "ospbr",
"ipam": {}
}
7 changes: 7 additions & 0 deletions pkg/openstack/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ func ReconcileOVNController(ctx context.Context, instance *corev1beta1.OpenStack
return false, err
}
return false, nil
} else if len(instance.Spec.Ovn.Template.OVNController.NicMappings) == 0 {
// If nicMappings is not configured there's no need to start ovn-controller
Log.Info("OVN Controller has no nicMappings configured, forcing ready condition to true.")
if _, err := EnsureDeleted(ctx, helper, OVNController); err != nil {
return false, err
}
return true, nil
}

ovnControllerSpec := &instance.Spec.Ovn.Template.OVNController
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc apply -n $NAMESPACE -f ../../../../config/samples/nad_datacentre.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc kustomize ../../../../config/samples/base/openstackcontrolplane | oc apply -n $NAMESPACE -f -
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
timeout: 60
commands:
- script: |
oc patch openstackcontrolplane -n $NAMESPACE openstack-basic --type='json' -p='[{
"op": "replace",
"path": "/spec/ovn/template/ovnController/nicMappings",
"value":{"datacentre":"ospbr"}
}]'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Pod
metadata:
labels:
service: ovn-controller
status:
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
labels:
service: ovn-controller-ovs
status:
phase: Running
---
# Used temporarily for testing as step 4 is failing
# bc it doesn't find the CR
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: |
oc get OpenStackControlPlane -A
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 300
commands:
- script: |
ovs_controller_pod_count=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs --no-headers=true --ignore-not-found=true | wc -l)
ovn_controller_pod_count=$(oc get pod -n $NAMESPACE -l service=ovn-controller --no-headers=true --ignore-not-found=true | wc -l)
if [ $ovs_controller_pod_count -eq 0 ] && [ $ovn_controller_pod_count -eq 0 ]; then
exit 0
fi
exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
timeout: 60
commands:
- script: |
oc patch OpenStackControlPlane -n $NAMESPACE openstack-basic --type='json' -p='[{
"op": "remove",
"path": "/spec/ovn/template/ovnController/nicMappings",
}]'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: core.openstack.org/v1beta1
kind: OpenStackControlPlane
name: openstack
commands:
- script: |
oc delete --ignore-not-found=true -n $NAMESPACE pvc \
srv-swift-storage-0
oc delete secret --ignore-not-found=true combined-ca-bundle -n $NAMESPACE
oc delete secret -l service-cert -n $NAMESPACE
oc delete secret -l ca-cert -n $NAMESPACE
Loading

0 comments on commit d68c339

Please sign in to comment.