Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hongliangl committed Jun 13, 2022
1 parent 58abaf6 commit f5a9d68
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 39 deletions.
22 changes: 1 addition & 21 deletions pkg/agent/controller/noderoute/node_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"antrea.io/antrea/pkg/ovs/ovsconfig"
utilip "antrea.io/antrea/pkg/util/ip"
"antrea.io/antrea/pkg/util/k8s"
"antrea.io/antrea/pkg/util/runtime"
)

const (
Expand Down Expand Up @@ -203,27 +202,8 @@ func (c *Controller) removeStaleGatewayRoutes() error {
desiredPodCIDRs = append(desiredPodCIDRs, podCIDRs...)
}

// TODO: This is not the best place to keep the ClusterIP Service routes.
desiredClusterIPSvcIPs := map[string]bool{}
if c.proxyAll && runtime.IsWindowsPlatform() {
// The route for virtual IP -> antrea-gw0 should be always kept.
desiredClusterIPSvcIPs[config.VirtualServiceIPv4.String()] = true

svcs, err := c.svcLister.List(labels.Everything())
for _, svc := range svcs {
for _, ip := range svc.Spec.ClusterIPs {
desiredClusterIPSvcIPs[ip] = true
}
}
if err != nil {
return fmt.Errorf("error when listing ClusterIP Service IPs: %v", err)
}
}

// routeClient will remove orphaned routes whose destinations are not in desiredPodCIDRs.
// If proxyAll enabled, it will also remove routes that are for Windows ClusterIP Services
// which no longer exist.
if err := c.routeClient.Reconcile(desiredPodCIDRs, desiredClusterIPSvcIPs); err != nil {
if err := c.routeClient.Reconcile(desiredPodCIDRs); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/route/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Interface interface {

// Reconcile should remove orphaned routes and related configuration based on the desired podCIDRs and Service IPs.
// If IPv6 is enabled in the cluster, Reconcile should also remove the orphaned IPv6 neighbors.
Reconcile(podCIDRs []string, svcIPs map[string]bool) error
Reconcile(podCIDRs []string) error

// AddRoutes should add routes to the provided podCIDR.
// It should override the routes if they already exist, without error.
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/route/route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ func (c *Client) initServiceIPRoutes() error {
}

// Reconcile removes orphaned podCIDRs from ipset and removes routes to orphaned podCIDRs
// based on the desired podCIDRs. svcIPs are used for Windows only.
func (c *Client) Reconcile(podCIDRs []string, svcIPs map[string]bool) error {
// based on the desired podCIDRs.
func (c *Client) Reconcile(podCIDRs []string) error {
desiredPodCIDRs := sets.NewString(podCIDRs...)
// Get the peer IPv6 gateways from pod CIDRs
desiredIPv6GWs := getIPv6Gateways(podCIDRs)
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/route/route_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Client) initServiceIPRoutes() error {

// Reconcile removes the orphaned routes and related configuration based on the desired podCIDRs and Service IPs. Only
// the route entries on the host gateway interface are stored in the cache.
func (c *Client) Reconcile(podCIDRs []string, svcIPs map[string]bool) error {
func (c *Client) Reconcile(podCIDRs []string) error {
desiredPodCIDRs := sets.NewString(podCIDRs...)
routes, err := c.listIPRoutesOnGW()
if err != nil {
Expand Down
25 changes: 11 additions & 14 deletions pkg/agent/route/route_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ func TestRouteOperation(t *testing.T) {
_, destCIDR2, _ := net.ParseCIDR(dest2)

client, err := NewClient(&config.NetworkConfig{}, true, false, false, false)
svcStr1 := "1.1.0.10"
svcIP1 := net.ParseIP(svcStr1)
svcIPNet1 := util.NewIPNet(svcIP1)
svcStr2 := "1.1.0.11"
svcIP2 := net.ParseIP(svcStr2)
svcIPNet2 := util.NewIPNet(svcIP2)
svcIP1 := net.ParseIP("1.1.0.1")
_, expectedClusterIPNet1, _ := net.ParseCIDR("1.1.0.1/32")
svcIP2 := net.ParseIP("1.1.0.7")
_, expectedClusterIPNet2, _ := net.ParseCIDR("1.1.0.0/29")

require.Nil(t, err)
nodeConfig := &config.NodeConfig{
Expand Down Expand Up @@ -86,27 +84,26 @@ func TestRouteOperation(t *testing.T) {

err = client.AddClusterIPRoute(svcIP1)
require.Nil(t, err)
route3, err := util.GetNetRoutes(gwLink, svcIPNet1)
route3, err := util.GetNetRoutes(gwLink, expectedClusterIPNet1)
require.Nil(t, err)
assert.Equal(t, 1, len(route3))

err = client.AddClusterIPRoute(svcIP2)
require.Nil(t, err)
route4, err := util.GetNetRoutes(gwLink, svcIPNet2)
route4, err := util.GetNetRoutes(gwLink, expectedClusterIPNet1)
require.Nil(t, err)
assert.Equal(t, 0, len(route4)) // Old ClusterIP route is expected to be deleted.
require.Nil(t, err)
route4, err = util.GetNetRoutes(gwLink, expectedClusterIPNet2) // New ClusterIP route is expected to be installed.
require.Nil(t, err)
assert.Equal(t, 1, len(route4))

err = client.Reconcile([]string{dest2}, map[string]bool{svcIPNet1.String(): true})
err = client.Reconcile([]string{dest2})
require.Nil(t, err)

routes5, err := util.GetNetRoutes(gwLink, destCIDR1)
require.Nil(t, err)
assert.Equal(t, 0, len(routes5))

routes6, err := util.GetNetRoutes(gwLink, svcIPNet2)
require.Nil(t, err)
assert.Equal(t, 0, len(routes6))

err = client.DeleteRoutes(destCIDR2)
require.Nil(t, err)
routes7, err := util.GetNetRoutes(gwLink, destCIDR2)
Expand Down

0 comments on commit f5a9d68

Please sign in to comment.