Skip to content

Commit b3b380e

Browse files
oilbeaterclaude
andcommitted
fix: avoid OVN northd "No path for static route" warning on startup
During controller startup, default gateway static routes (0.0.0.0/0 and ::/0) were added to the OVN logical router before the join subnet's Logical Router Port was created, causing OVN northd to warn about unreachable next hops. This fix ensures routes are only added after the join subnet's OVN Logical Switch and LRP exist: 1. Remove addNodeGatewayStaticRoute() call from syncNodeRoutes() which runs during init phase before any OVN logical switches are created. 2. Add LogicalSwitchExists check in handleAddOrUpdateVpc() to requeue the VPC if the join subnet's logical switch is not yet ready, avoiding the race between VPC worker and Subnet worker. 3. Remove redundant addNodeGatewayStaticRoute() call from handleAddNode() since handleAddOrUpdateVpc() already manages default route reconciliation as part of VPC route diffing. Also remove the now-unused function. Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 7cb33fa commit b3b380e

File tree

3 files changed

+11
-45
lines changed

3 files changed

+11
-45
lines changed

pkg/controller/init.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,6 @@ func (c *Controller) syncNodeRoutes() error {
904904
return err
905905
}
906906

907-
if err := c.addNodeGatewayStaticRoute(); err != nil {
908-
klog.Errorf("failed to add static route for node gateway")
909-
return err
910-
}
911907
return nil
912908
}
913909

pkg/controller/node.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ func (c *Controller) handleAddNode(key string) error {
241241
}
242242
}
243243

244-
if err := c.addNodeGatewayStaticRoute(); err != nil {
245-
klog.Errorf("failed to add static route for node gw: %v", err)
246-
return err
247-
}
248-
249244
patch := util.KVPatch{
250245
util.IPAddressAnnotation: ipStr,
251246
util.MacAddressAnnotation: mac,
@@ -918,42 +913,6 @@ func (c *Controller) UpdateChassisTag(node *v1.Node) error {
918913
return nil
919914
}
920915

921-
func (c *Controller) addNodeGatewayStaticRoute() error {
922-
// If user not manage static route for default vpc, just add route about ovn-default to join
923-
if vpc, err := c.vpcsLister.Get(c.config.ClusterRouter); err != nil || vpc.Spec.StaticRoutes != nil {
924-
existRoute, err := c.OVNNbClient.ListLogicalRouterStaticRoutes(c.config.ClusterRouter, nil, nil, "", nil)
925-
if err != nil {
926-
klog.Errorf("failed to get vpc %s static route list, %v", c.config.ClusterRouter, err)
927-
}
928-
if len(existRoute) != 0 {
929-
klog.Infof("skip add static route for node gw")
930-
return nil
931-
}
932-
}
933-
dstCidr := "0.0.0.0/0,::/0"
934-
for cidrBlock := range strings.SplitSeq(dstCidr, ",") {
935-
for nextHop := range strings.SplitSeq(c.config.NodeSwitchGateway, ",") {
936-
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(nextHop) {
937-
continue
938-
}
939-
940-
if err := c.addStaticRouteToVpc(
941-
c.config.ClusterRouter,
942-
&kubeovnv1.StaticRoute{
943-
Policy: kubeovnv1.PolicyDst,
944-
CIDR: cidrBlock,
945-
NextHopIP: nextHop,
946-
RouteTable: util.MainRouteTable,
947-
},
948-
); err != nil {
949-
klog.Errorf("failed to add static route for node gw: %v", err)
950-
return err
951-
}
952-
}
953-
}
954-
return nil
955-
}
956-
957916
func (c *Controller) getPolicyRouteParams(cidr string, priority int) (*strset.Set, map[string]string, error) {
958917
ipSuffix := "ip4"
959918
if util.CheckProtocol(cidr) == kubeovnv1.ProtocolIPv6 {

pkg/controller/vpc.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
383383
c.addOrUpdateVpcQueue.Add(vpc.Name)
384384
return nil
385385
}
386+
387+
// Ensure the join subnet's OVN Logical Switch (and its LRP) has been created
388+
// before adding default routes. Otherwise, OVN northd will warn about unreachable next hops.
389+
if exist, err := c.OVNNbClient.LogicalSwitchExists(c.config.NodeSwitch); err != nil {
390+
klog.Errorf("failed to check logical switch %s existence: %v", c.config.NodeSwitch, err)
391+
return err
392+
} else if !exist {
393+
klog.Infof("logical switch %s not ready, requeue vpc %s", c.config.NodeSwitch, vpc.Name)
394+
c.addOrUpdateVpcQueue.Add(vpc.Name)
395+
return nil
396+
}
386397
gatewayV4, gatewayV6 := util.SplitStringIP(joinSubnet.Spec.Gateway)
387398
if gatewayV4 != "" {
388399
for table := range staticRouteMapping {

0 commit comments

Comments
 (0)