Skip to content

Commit 9ef8018

Browse files
Merge pull request #413 from karelyatin/OSPRH-8514
Propogate invalid nic mapping error to ovncontroller status
2 parents fa4c660 + 830a363 commit 9ef8018

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

controllers/ovncontroller_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
489489
networkAttachments, err := ovncontroller.CreateOrUpdateAdditionalNetworks(ctx, helper, instance, ovsServiceLabels)
490490
if err != nil {
491491
Log.Info(fmt.Sprintf("Failed to create additional networks: %s", err))
492+
instance.Status.Conditions.Set(condition.FalseCondition(
493+
condition.NetworkAttachmentsReadyCondition,
494+
condition.ErrorReason,
495+
condition.SeverityWarning,
496+
condition.NetworkAttachmentsReadyErrorMessage,
497+
err.Error()))
492498
return ctrl.Result{}, err
493499
}
494500

tests/functional/ovncontroller_controller_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,68 @@ var _ = Describe("OVNController controller", func() {
726726
})
727727
})
728728

729+
When("OVNController is created with invalid nic mappings", func() {
730+
var OVNControllerName types.NamespacedName
731+
BeforeEach(func() {
732+
dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1)
733+
DeferCleanup(DeleteOVNDBClusters, dbs)
734+
spec := GetDefaultOVNControllerSpec()
735+
spec.NicMappings = map[string]string{
736+
"<invalid>": "<nic>",
737+
}
738+
instance := CreateOVNController(namespace, spec)
739+
OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()}
740+
DeferCleanup(th.DeleteInstance, instance)
741+
})
742+
743+
It("reports error for invalid nicMappings", func() {
744+
Eventually(func(g Gomega) {
745+
getter := ConditionGetterFunc(OVNControllerConditionGetter)
746+
conditions := getter.GetConditions(OVNControllerName)
747+
g.Expect(conditions).NotTo(
748+
BeNil(), "Status.Conditions in nil")
749+
netCondition := conditions.Get(condition.NetworkAttachmentsReadyCondition)
750+
g.Expect(netCondition.Message).Should(
751+
ContainSubstring("a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.'"))
752+
}, timeout, interval).Should(Succeed())
753+
})
754+
755+
It("reports success when nicMappings updated to valid value", func() {
756+
// Update Interface in NicMappings
757+
Eventually(func(g Gomega) {
758+
ovnController := GetOVNController(OVNControllerName)
759+
ovnController.Spec.NicMappings = map[string]string{
760+
"validnet": "enp3s0.100",
761+
}
762+
g.Expect(k8sClient.Update(ctx, ovnController)).Should(Succeed())
763+
}, timeout, interval).Should(Succeed())
764+
765+
nad := types.NamespacedName{
766+
Namespace: OVNControllerName.Namespace,
767+
Name: "validnet",
768+
}
769+
770+
// Ensure OwnerReferences set correctly for the updated Network Attachment
771+
Eventually(func(g Gomega) {
772+
g.Expect(GetNAD(nad).ObjectMeta.OwnerReferences[0].Name).To(Equal(
773+
OVNControllerName.Name))
774+
}, timeout, interval).Should(Succeed())
775+
776+
// Ensure NetworkCondition ready
777+
th.ExpectCondition(
778+
OVNControllerName,
779+
ConditionGetterFunc(OVNControllerConditionGetter),
780+
condition.NetworkAttachmentsReadyCondition,
781+
corev1.ConditionTrue,
782+
)
783+
// Ensure Interface updated in the Network Attachment
784+
Eventually(func(g Gomega) {
785+
g.Expect(GetNAD(nad).Spec.Config).Should(
786+
ContainSubstring("enp3s0.100"))
787+
}, timeout, interval).Should(Succeed())
788+
})
789+
})
790+
729791
When("OVNController is created with networkAttachment and nic configs", func() {
730792
BeforeEach(func() {
731793
dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1)

0 commit comments

Comments
 (0)