From d3589d82f6c36c34b0fbf353c77581ad2a11c456 Mon Sep 17 00:00:00 2001 From: Nadia Pinaeva Date: Tue, 4 Jul 2023 13:33:34 +0200 Subject: [PATCH] fix external gateway test that cleans up namespace annotation. It used to fail parsing namespace annotations, because they were empty. Add RunAPBExternalPolicyController call to handle apbroutes. Signed-off-by: Nadia Pinaeva --- .../ovn/controller/apbroute/external_controller_policy.go | 2 +- go-controller/pkg/ovn/egressgw_test.go | 8 ++++++-- go-controller/pkg/ovn/namespace.go | 8 +++++--- go-controller/pkg/util/namespace_annotation.go | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/go-controller/pkg/ovn/controller/apbroute/external_controller_policy.go b/go-controller/pkg/ovn/controller/apbroute/external_controller_policy.go index 90f587a83e8..73139742f74 100644 --- a/go-controller/pkg/ovn/controller/apbroute/external_controller_policy.go +++ b/go-controller/pkg/ovn/controller/apbroute/external_controller_policy.go @@ -296,7 +296,7 @@ func (m *externalPolicyManager) processStaticHopsGatewayInformation(hops []*admi for _, h := range hops { ip := net.ParseIP(h.IP) if ip == nil { - return nil, fmt.Errorf("could not parse routing external gw annotation value '%s'", h.IP) + return nil, fmt.Errorf("could not parse routing static gw annotation value '%s'", h.IP) } gwList.InsertOverwrite(newGatewayInfo(sets.New(ip.String()), h.BFDEnabled)) } diff --git a/go-controller/pkg/ovn/egressgw_test.go b/go-controller/pkg/ovn/egressgw_test.go index c4c210bd8d0..7538a6a8bc6 100644 --- a/go-controller/pkg/ovn/egressgw_test.go +++ b/go-controller/pkg/ovn/egressgw_test.go @@ -2490,6 +2490,8 @@ var _ = ginkgo.Describe("OVN Egress Gateway Operations", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) err = fakeOvn.controller.WatchPods() gomega.Expect(err).NotTo(gomega.HaveOccurred()) + fakeOvn.RunAPBExternalPolicyController() + asIndex := getHybridRouteAddrSetDbIDs("node1", DefaultNetworkControllerName) asv4, _ := addressset.GetHashNamesForAS(asIndex) nbWithLRP := []libovsdbtest.TestData{ @@ -2546,7 +2548,9 @@ var _ = ginkgo.Describe("OVN Egress Gateway Operations", func() { }, } - gomega.Eventually(func() string { return getPodAnnotations(fakeOvn.fakeClient.KubeClient, t.namespace, t.podName) }, 2).Should(gomega.MatchJSON(t.getAnnotationsJson())) + gomega.Eventually(func() string { + return getPodAnnotations(fakeOvn.fakeClient.KubeClient, t.namespace, t.podName) + }, 2).Should(gomega.MatchJSON(t.getAnnotationsJson())) gomega.Eventually(fakeOvn.nbClient).Should(libovsdbtest.HaveData(nbWithLRP)) ginkgo.By("Removing the namespace annotation") @@ -2555,7 +2559,7 @@ var _ = ginkgo.Describe("OVN Egress Gateway Operations", func() { gomega.Expect(err).NotTo(gomega.HaveOccurred()) gomega.Eventually(fakeOvn.nbClient).Should(libovsdbtest.HaveData(nbWithLRP)) - + checkAPBRouteStatus(fakeOvn, "policy", false) return nil } diff --git a/go-controller/pkg/ovn/namespace.go b/go-controller/pkg/ovn/namespace.go index 937c7ce5d95..634b371ab84 100644 --- a/go-controller/pkg/ovn/namespace.go +++ b/go-controller/pkg/ovn/namespace.go @@ -203,9 +203,11 @@ func (oc *DefaultNetworkController) updateNamespace(old, newer *kapi.Namespace) if err != nil { errors = append(errors, err) } else { - err = oc.addExternalGWsForNamespace(gatewayInfo{gws: exGateways, bfdEnabled: newBFDEnabled}, nsInfo, old.Name) - if err != nil { - errors = append(errors, err) + if exGateways.Len() != 0 { + err = oc.addExternalGWsForNamespace(gatewayInfo{gws: exGateways, bfdEnabled: newBFDEnabled}, nsInfo, old.Name) + if err != nil { + errors = append(errors, err) + } } } // if new annotation is empty, exgws were removed, may need to add SNAT per pod diff --git a/go-controller/pkg/util/namespace_annotation.go b/go-controller/pkg/util/namespace_annotation.go index 8ce839ebd38..7b6fd8b5136 100644 --- a/go-controller/pkg/util/namespace_annotation.go +++ b/go-controller/pkg/util/namespace_annotation.go @@ -34,6 +34,9 @@ func UpdateExternalGatewayPodIPsAnnotation(k kube.Interface, namespace string, e func ParseRoutingExternalGWAnnotation(annotation string) (sets.Set[string], error) { ipTracker := sets.New[string]() + if annotation == "" { + return ipTracker, nil + } for _, v := range strings.Split(annotation, ",") { parsedAnnotation := net.ParseIP(v) if parsedAnnotation == nil {