Skip to content

Commit 38309b2

Browse files
committed
Fix that Service routes may get lost when starting on Windows
Fix #4467 Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
1 parent b503a46 commit 38309b2

8 files changed

Lines changed: 24 additions & 41 deletions

File tree

pkg/agent/controller/noderoute/node_route_controller.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"antrea.io/antrea/pkg/ovs/ovsconfig"
4343
utilip "antrea.io/antrea/pkg/util/ip"
4444
"antrea.io/antrea/pkg/util/k8s"
45-
"antrea.io/antrea/pkg/util/runtime"
4645
)
4746

4847
const (
@@ -72,7 +71,6 @@ type Controller struct {
7271
nodeInformer coreinformers.NodeInformer
7372
nodeLister corelisters.NodeLister
7473
nodeListerSynced cache.InformerSynced
75-
svcLister corelisters.ServiceLister
7674
queue workqueue.RateLimitingInterface
7775
// installedNodes records routes and flows installation states of Nodes.
7876
// The key is the host name of the Node, the value is the nodeRouteInfo of the Node.
@@ -102,7 +100,6 @@ func NewNodeRouteController(
102100
ipsecCertificateManager ipseccertificate.Manager,
103101
) *Controller {
104102
nodeInformer := informerFactory.Core().V1().Nodes()
105-
svcLister := informerFactory.Core().V1().Services()
106103
controller := &Controller{
107104
kubeClient: kubeClient,
108105
ovsBridgeClient: ovsBridgeClient,
@@ -114,7 +111,6 @@ func NewNodeRouteController(
114111
nodeInformer: nodeInformer,
115112
nodeLister: nodeInformer.Lister(),
116113
nodeListerSynced: nodeInformer.Informer().HasSynced,
117-
svcLister: svcLister.Lister(),
118114
queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "noderoute"),
119115
installedNodes: cache.NewIndexer(nodeRouteInfoKeyFunc, cache.Indexers{nodeRouteInfoPodCIDRIndexName: nodeRouteInfoPodCIDRIndexFunc}),
120116
wireGuardClient: wireguardClient,
@@ -203,27 +199,10 @@ func (c *Controller) removeStaleGatewayRoutes() error {
203199
desiredPodCIDRs = append(desiredPodCIDRs, podCIDRs...)
204200
}
205201

206-
// TODO: This is not the best place to keep the ClusterIP Service routes.
207-
desiredClusterIPSvcIPs := map[string]bool{}
208-
if c.proxyAll && runtime.IsWindowsPlatform() {
209-
// The route for virtual IP -> antrea-gw0 should be always kept.
210-
desiredClusterIPSvcIPs[config.VirtualServiceIPv4.String()] = true
211-
212-
svcs, err := c.svcLister.List(labels.Everything())
213-
for _, svc := range svcs {
214-
for _, ip := range svc.Spec.ClusterIPs {
215-
desiredClusterIPSvcIPs[ip] = true
216-
}
217-
}
218-
if err != nil {
219-
return fmt.Errorf("error when listing ClusterIP Service IPs: %v", err)
220-
}
221-
}
222-
223202
// routeClient will remove orphaned routes whose destinations are not in desiredPodCIDRs.
224203
// If proxyAll enabled, it will also remove routes that are for Windows ClusterIP Services
225-
// which no longer exist.
226-
if err := c.routeClient.Reconcile(desiredPodCIDRs, desiredClusterIPSvcIPs); err != nil {
204+
// which no longer exists.
205+
if err := c.routeClient.Reconcile(desiredPodCIDRs); err != nil {
227206
return err
228207
}
229208
return nil

pkg/agent/route/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Interface interface {
2929

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

3434
// AddRoutes should add routes to the provided podCIDR.
3535
// It should override the routes if they already exist, without error.

pkg/agent/route/route_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ func (c *Client) initServiceIPRoutes() error {
843843

844844
// Reconcile removes orphaned podCIDRs from ipset and removes routes to orphaned podCIDRs
845845
// based on the desired podCIDRs. svcIPs are used for Windows only.
846-
func (c *Client) Reconcile(podCIDRs []string, svcIPs map[string]bool) error {
846+
func (c *Client) Reconcile(podCIDRs []string) error {
847847
desiredPodCIDRs := sets.NewString(podCIDRs...)
848848
// Get the peer IPv6 gateways from pod CIDRs
849849
desiredIPv6GWs := getIPv6Gateways(podCIDRs)

pkg/agent/route/route_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func TestReconcile(t *testing.T) {
622622
{IP: net.ParseIP("2001:ab03:cd04:55ee:100b::1")}, // non-existing podCIDR, should be deleted.
623623
}, nil)
624624
mockNetlink.EXPECT().NeighDel(&netlink.Neigh{IP: net.ParseIP("2001:ab03:cd04:55ee:100b::1")})
625-
assert.NoError(t, c.Reconcile(podCIDRs, nil))
625+
assert.NoError(t, c.Reconcile(podCIDRs))
626626
}
627627

628628
func TestAddRoutes(t *testing.T) {

pkg/agent/route/route_windows.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (c *Client) initServiceIPRoutes() error {
122122

123123
// Reconcile removes the orphaned routes and related configuration based on the desired podCIDRs and Service IPs. Only
124124
// the route entries on the host gateway interface are stored in the cache.
125-
func (c *Client) Reconcile(podCIDRs []string, svcIPs map[string]bool) error {
125+
func (c *Client) Reconcile(podCIDRs []string) error {
126126
desiredPodCIDRs := sets.NewString(podCIDRs...)
127127
routes, err := c.listRoutes()
128128
if err != nil {
@@ -133,8 +133,8 @@ func (c *Client) Reconcile(podCIDRs []string, svcIPs map[string]bool) error {
133133
c.hostRoutes.Store(dst, rt)
134134
continue
135135
}
136-
if _, ok := svcIPs[dst]; ok {
137-
c.hostRoutes.Store(dst, rt)
136+
// Don't delete the routes which are added by AntreaProxy.
137+
if c.isServiceRoute(rt) {
138138
continue
139139
}
140140
err := util.RemoveNetRoute(rt)
@@ -260,8 +260,8 @@ func (c *Client) addVirtualServiceIPRoute(isIPv6 bool) error {
260260

261261
// TODO: Follow the code style in Linux that maintains one Service CIDR.
262262
func (c *Client) addServiceRoute(svcIP net.IP) error {
263-
obj, found := c.hostRoutes.Load(svcIP.String())
264263
svcIPNet := util.NewIPNet(svcIP)
264+
obj, found := c.hostRoutes.Load(svcIPNet.String())
265265

266266
// Route: Service IP -> VirtualServiceIPv4 (169.254.0.253)
267267
route := &util.Route{
@@ -332,6 +332,14 @@ func (c *Client) UnMigrateRoutesFromGw(route *net.IPNet, linkName string) error
332332
func (c *Client) Run(stopCh <-chan struct{}) {
333333
}
334334

335+
func (c *Client) isServiceRoute(route *util.Route) bool {
336+
// If the destination IP or gateway IP is virtual Service IP , then it is a route which is added by AntreaProxy.
337+
if route.DestinationSubnet.IP.Equal(config.VirtualServiceIPv4) || route.GatewayAddress.Equal(config.VirtualServiceIPv4) {
338+
return true
339+
}
340+
return false
341+
}
342+
335343
func (c *Client) listRoutes() (map[string]*util.Route, error) {
336344
routes, err := util.GetNetRoutesAll()
337345
if err != nil {

pkg/agent/route/route_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestRouteOperation(t *testing.T) {
9696
require.Nil(t, err)
9797
assert.Equal(t, 1, len(route4))
9898

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

102102
routes5, err := util.GetNetRoutes(gwLink, destCIDR1)

pkg/agent/route/testing/mock_route.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/agent/route_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ func TestReconcile(t *testing.T) {
517517
addedRoutes []peer
518518
desiredPeerCIDRs []string
519519
desiredNodeIPs []string
520-
desiredServices map[string]bool
521520
// expectations
522521
expRoutes map[string]netlink.Link
523522
}{
@@ -530,7 +529,6 @@ func TestReconcile(t *testing.T) {
530529
},
531530
desiredPeerCIDRs: []string{"10.10.20.0/24"},
532531
desiredNodeIPs: []string{remotePeerIP.String()},
533-
desiredServices: map[string]bool{"200.200.10.10": true},
534532
expRoutes: map[string]netlink.Link{"10.10.20.0/24": gwLink, "10.10.30.0/24": nil},
535533
},
536534
{
@@ -542,7 +540,6 @@ func TestReconcile(t *testing.T) {
542540
},
543541
desiredPeerCIDRs: []string{"10.10.20.0/24"},
544542
desiredNodeIPs: []string{localPeerIP.String()},
545-
desiredServices: map[string]bool{"200.200.10.10": true},
546543
expRoutes: map[string]netlink.Link{"10.10.20.0/24": nodeLink, "10.10.30.0/24": nil},
547544
},
548545
{
@@ -556,7 +553,6 @@ func TestReconcile(t *testing.T) {
556553
},
557554
desiredPeerCIDRs: []string{"10.10.20.0/24", "10.10.40.0/24"},
558555
desiredNodeIPs: []string{localPeerIP.String(), remotePeerIP.String()},
559-
desiredServices: map[string]bool{"200.200.10.10": true},
560556
expRoutes: map[string]netlink.Link{"10.10.20.0/24": nodeLink, "10.10.30.0/24": nil, "10.10.40.0/24": gwLink, "10.10.50.0/24": nil},
561557
},
562558
}
@@ -574,7 +570,7 @@ func TestReconcile(t *testing.T) {
574570
assert.NoError(t, routeClient.AddRoutes(peerNet, tc.nodeName, route.peerIP, peerGwIP), "adding routes failed")
575571
}
576572

577-
assert.NoError(t, routeClient.Reconcile(tc.desiredPeerCIDRs, tc.desiredServices), "reconcile failed")
573+
assert.NoError(t, routeClient.Reconcile(tc.desiredPeerCIDRs), "reconcile failed")
578574

579575
for dst, uplink := range tc.expRoutes {
580576
expNum := 0

0 commit comments

Comments
 (0)