in pkg/controller/route/manager.go [79:151]
func (r *ReconcileRoute) syncTableRoutes(ctx context.Context, table string, nodes *v1.NodeList) error {
routes, err := r.cloud.ListRoute(ctx, table)
if err != nil {
return fmt.Errorf("error listing routes: %v", err)
}
var clusterCIDR *net.IPNet
if ctrlCfg.ControllerCFG.ClusterCIDR != "" {
_, clusterCIDR, err = net.ParseCIDR(ctrlCfg.ControllerCFG.ClusterCIDR)
if err != nil {
return fmt.Errorf("error parse cluster cidr %s: %s", ctrlCfg.ControllerCFG.ClusterCIDR, err)
}
}
for _, route := range routes {
contains, _, err := containsRoute(clusterCIDR, route.DestinationCIDR)
if err != nil {
klog.Errorf("error contains route %v <- %v, error %v ", clusterCIDR, route.DestinationCIDR, err)
continue
}
if !contains {
continue
}
if conflictWithNodes(route.DestinationCIDR, nodes) {
klog.Infof("delete route %s, %s", route.Name, route.DestinationCIDR)
if err = deleteRouteForInstance(ctx, table, route.ProviderId, route.DestinationCIDR, r.cloud); err != nil {
klog.Errorf("Could not delete route %s %s from table %s, %s", route.Name, route.DestinationCIDR, table, err.Error())
continue
}
klog.Infof("Delete route %s, %s from table %s SUCCESS.", route.Name, route.DestinationCIDR, table)
}
}
for _, node := range nodes.Items {
if !r.configRoutes || helper.HasExcludeLabel(&node) {
continue
}
readyCondition, ok := helper.FindCondition(node.Status.Conditions, v1.NodeReady)
if ok && readyCondition.Status == v1.ConditionUnknown {
continue
}
prvdId := node.Spec.ProviderID
if prvdId == "" {
continue
}
_, ipv4RouteCidr, err := getIPv4RouteForNode(&node)
if err != nil || ipv4RouteCidr == "" {
continue
}
err = r.addRouteForNode(ctx, table, ipv4RouteCidr, prvdId, &node, routes)
if err != nil {
klog.Errorf("try create route error: %s", err.Error())
r.record.Event(
&node,
v1.EventTypeWarning,
"CreateRouteFailed",
fmt.Sprintf("Create Route Failed for %s reason: %s", table, err),
)
continue
}
networkCondition, ok := helper.FindCondition(node.Status.Conditions, v1.NodeNetworkUnavailable)
if !ok || networkCondition.Status != v1.ConditionFalse {
if err := r.updateNetworkingCondition(ctx, &node, true); err != nil {
klog.Errorf("update node %s network condition err: %s", node.Name, err.Error())
}
}
}
return nil
}