Skip to content

Commit

Permalink
fix external gateway test that cleans up namespace annotation.
Browse files Browse the repository at this point in the history
It used to fail parsing namespace annotations, because they were empty.
Add RunAPBExternalPolicyController call to handle apbroutes.

Signed-off-by: Nadia Pinaeva <[email protected]>
  • Loading branch information
npinaeva committed Jul 4, 2023
1 parent 2339d90 commit d3589d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
8 changes: 6 additions & 2 deletions go-controller/pkg/ovn/egressgw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand All @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions go-controller/pkg/ovn/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go-controller/pkg/util/namespace_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d3589d8

Please sign in to comment.