Skip to content

Commit

Permalink
Remove watchers when egress IP is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Constantinescu <aconstan@redhat.com>

Test cases checking watcher function for multiple ADD/DELETE
  • Loading branch information
alexanderConstantinescu committed Aug 3, 2020
1 parent de6602f commit 025120d
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 32 deletions.
8 changes: 8 additions & 0 deletions go-controller/pkg/ovn/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ func (oc *Controller) deleteEgressIP(eIP *egressipv1.EgressIP) error {

oc.egressIPNamespaceHandlerMutex.Lock()
defer oc.egressIPNamespaceHandlerMutex.Unlock()
nH := oc.egressIPNamespaceHandlerCache[getEgressIPKey(eIP)]
if err := oc.watchFactory.RemoveNamespaceHandler(&nH); err != nil {
klog.Errorf("Unable to remove watchFactory namespace handler, err: %v", err)
}
delete(oc.egressIPNamespaceHandlerCache, getEgressIPKey(eIP))

oc.egressIPPodHandlerMutex.Lock()
defer oc.egressIPPodHandlerMutex.Unlock()
pH := oc.egressIPPodHandlerCache[getEgressIPKey(eIP)]
if err := oc.watchFactory.RemovePodHandler(&pH); err != nil {
klog.Errorf("Unable to remove watchFactory pod handler, err: %v", err)
}
delete(oc.egressIPPodHandlerCache, getEgressIPKey(eIP))

namespaces, err := oc.kube.GetNamespaces(eIP.Spec.NamespaceSelector)
Expand Down
22 changes: 11 additions & 11 deletions go-controller/pkg/ovn/egressip_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --data=bare --format=table --no-heading --columns=options find logical_router name=GR_%s options:lb_force_snat_ip!=-", node2.name),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeGatewayRouterIP),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeLogicalRouterIPv6),
},
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down Expand Up @@ -190,12 +190,12 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --data=bare --format=table --no-heading --columns=options find logical_router name=GR_%s options:lb_force_snat_ip!=-", node2.name),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeGatewayRouterIP),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeLogicalRouterIPv6),
},
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down Expand Up @@ -286,12 +286,12 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --data=bare --format=table --no-heading --columns=options find logical_router name=GR_%s options:lb_force_snat_ip!=-", node2.name),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeGatewayRouterIP),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeLogicalRouterIPv6),
},
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", podUpdate.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", podUpdate.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down Expand Up @@ -414,12 +414,12 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --data=bare --format=table --no-heading --columns=options find logical_router name=GR_%s options:lb_force_snat_ip!=-", node2.name),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeGatewayRouterIP),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeLogicalRouterIPv6),
},
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down Expand Up @@ -561,12 +561,12 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --data=bare --format=table --no-heading --columns=options find logical_router name=GR_%s options:lb_force_snat_ip!=-", node2.name),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeGatewayRouterIP),
Output: fmt.Sprintf("lb_force_snat_ip=%s", nodeLogicalRouterIPv6),
},
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down Expand Up @@ -606,7 +606,7 @@ var _ = Describe("Local gateway mode EgressIP Operations with", func() {
)
fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeGatewayRouterIP, mark),
fmt.Sprintf("ovn-nbctl --timeout=15 lr-policy-add ovn_cluster_router 100 ip6.src == %s && ip6.dst == ::/0 reroute %s pkt_mark=%v", egressPod.Status.PodIP, nodeLogicalRouterIPv6, mark),
},
)

Expand Down
Loading

0 comments on commit 025120d

Please sign in to comment.