Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions go-controller/pkg/ovn/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ func (oc *Controller) deleteNodeForEgress(node *v1.Node) error {
func (oc *Controller) initClusterEgressPolicies(nodes []interface{}) {
v4ClusterSubnet, v6ClusterSubnet := getClusterSubnets()
createDefaultNoReroutePodPolicies(v4ClusterSubnet, v6ClusterSubnet)
oc.createDefaultNoRerouteServicePolicies(v4ClusterSubnet, v6ClusterSubnet)
go oc.checkEgressNodesReachability()
}

Expand Down Expand Up @@ -1134,6 +1135,25 @@ func getNodeInternalAddrs(node *v1.Node) (net.IP, net.IP) {
return v4Addr, v6Addr
}

// createDefaultNoRerouteServicePolicies ensures service reachability from the
// host network to any service backed by egress IP matching pods
func (oc *Controller) createDefaultNoRerouteServicePolicies(v4ClusterSubnet, v6ClusterSubnet []*net.IPNet) {
for _, v4Subnet := range v4ClusterSubnet {
_, stderr, err := util.RunOVNNbctl("--may-exist", "lr-policy-add", types.OVNClusterRouter, fmt.Sprintf("%v", types.DefaultNoRereoutePriority),
fmt.Sprintf("ip4.src == %s && ip4.dst == %s", v4Subnet.String(), config.Gateway.V4JoinSubnet), "allow")
if err != nil {
klog.Errorf("Unable to create IPv4 default no-reroute service policy, stderr: %s, err: %v", stderr, err)
}
}
for _, v6Subnet := range v6ClusterSubnet {
_, stderr, err := util.RunOVNNbctl("--may-exist", "lr-policy-add", types.OVNClusterRouter, fmt.Sprintf("%v", types.DefaultNoRereoutePriority),
fmt.Sprintf("ip6.src == %s && ip6.dst == %s", v6Subnet.String(), config.Gateway.V6JoinSubnet), "allow")
if err != nil {
klog.Errorf("Unable to create IPv6 default no-reroute service policy, stderr: %s, err: %v", stderr, err)
}
}
}

// createDefaultNoReroutePodPolicies ensures egress pods east<->west traffic with regular pods,
// i.e: ensuring that an egress pod can still communicate with a regular pod / service backed by regular pods
func createDefaultNoReroutePodPolicies(v4ClusterSubnet, v6ClusterSubnet []*net.IPNet) {
Expand Down
48 changes: 48 additions & 0 deletions go-controller/pkg/ovn/egressip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
},
)

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
gomega.Eventually(getEgressIPAllocatorSizeSafely).Should(gomega.Equal(2))
gomega.Expect(fakeOvn.controller.eIPC.allocator).To(gomega.HaveKey(node1.Name))
Expand Down Expand Up @@ -396,6 +402,13 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
fmt.Sprintf("ovn-nbctl --timeout=15 set logical_switch_port etor-GR_node1 options:nat-addresses=router"),
},
)

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
gomega.Eventually(getEgressIPAllocatorSizeSafely).Should(gomega.Equal(2))
gomega.Expect(fakeOvn.controller.eIPC.allocator).To(gomega.HaveKey(node1.Name))
Expand Down Expand Up @@ -1302,6 +1315,13 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
fmt.Sprintf("ovn-nbctl --timeout=15 set logical_switch_port etor-GR_node2 options:nat-addresses=router"),
},
)

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
gomega.Eventually(getEgressIPAllocatorSizeSafely).Should(gomega.Equal(0))
node1.Labels = map[string]string{
Expand Down Expand Up @@ -1374,6 +1394,12 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
return len(fakeOvn.controller.eIPC.allocator)
}

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
gomega.Eventually(allocatorItems).Should(gomega.Equal(0))

Expand Down Expand Up @@ -1443,6 +1469,7 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid find logical_router_policy priority=%s nexthop!=[]", types.EgressIPReroutePriority),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add ovn_cluster_router 101 ip4.src == 10.128.0.0/14 && ip4.dst == 10.128.0.0/14 allow"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

Expand Down Expand Up @@ -1573,8 +1600,10 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,match find logical_router_policy priority=100"),
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,logical_ip find nat"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
fakeOvn.controller.WatchEgressIP()

Expand Down Expand Up @@ -1667,8 +1696,10 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,match find logical_router_policy priority=100"),
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,logical_ip find nat"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
fakeOvn.controller.WatchEgressIP()

Expand Down Expand Up @@ -1789,6 +1820,13 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
fmt.Sprintf("ovn-nbctl --timeout=15 set logical_switch_port etor-GR_node2 options:nat-addresses=router"),
},
)

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.fakeExec.AddFakeCmd(
&ovntest.ExpectedCmd{
Cmd: fmt.Sprintf("ovn-nbctl --timeout=15 --if-exist get logical_router_port rtoj-GR_%s networks", node1.Name),
Expand Down Expand Up @@ -1950,6 +1988,12 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
},
)

fakeOvn.fakeExec.AddFakeCmdsNoOutputNoError(
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
fakeOvn.controller.WatchEgressIP()

Expand Down Expand Up @@ -2033,8 +2077,10 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,match find logical_router_policy priority=100"),
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,logical_ip find nat"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

fakeOvn.controller.WatchEgressNodes()
fakeOvn.controller.WatchEgressIP()

Expand Down Expand Up @@ -2160,6 +2206,7 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid find logical_router_policy priority=%s nexthop!=[]", types.EgressIPReroutePriority),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add ovn_cluster_router 101 ip4.src == 10.128.0.0/14 && ip4.dst == 10.128.0.0/14 allow"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

Expand Down Expand Up @@ -2300,6 +2347,7 @@ var _ = ginkgo.Describe("OVN master EgressIP Operations", func() {
[]string{
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,match find logical_router_policy priority=100"),
fmt.Sprintf("ovn-nbctl --timeout=15 --format=csv --data=bare --no-heading --columns=_uuid,external_ids,logical_ip find nat"),
fmt.Sprintf("ovn-nbctl --timeout=15 --may-exist lr-policy-add %s %v ip4.src == 10.128.0.0/14 && ip4.dst == %s allow", types.OVNClusterRouter, types.DefaultNoRereoutePriority, config.Gateway.V4JoinSubnet),
},
)

Expand Down