@@ -22,7 +22,6 @@ import (
22
22
23
23
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
24
24
"github.com/kubeovn/kube-ovn/pkg/ovs"
25
- "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
26
25
"github.com/kubeovn/kube-ovn/pkg/util"
27
26
)
28
27
@@ -271,15 +270,26 @@ func (c *Controller) handleAddNode(key string) error {
271
270
nodeIP , af = nodeIPv6 , 6
272
271
}
273
272
if nodeIP != "" {
274
- match := fmt .Sprintf ("ip%d.dst == %s" , af , nodeIP )
275
- action := ovnnb .LogicalRouterPolicyActionReroute
276
- externalIDs := map [string ]string {
277
- "vendor" : util .CniTypeName ,
278
- "node" : node .Name ,
279
- "address-family" : strconv .Itoa (af ),
280
- }
273
+ var (
274
+ match = fmt .Sprintf ("ip%d.dst == %s" , af , nodeIP )
275
+ action = kubeovnv1 .PolicyRouteActionReroute
276
+ externalIDs = map [string ]string {
277
+ "vendor" : util .CniTypeName ,
278
+ "node" : node .Name ,
279
+ "address-family" : strconv .Itoa (af ),
280
+ }
281
+ )
281
282
klog .Infof ("add policy route for router: %s, match %s, action %s, nexthop %s, externalID %v" , c .config .ClusterRouter , match , action , ip , externalIDs )
282
- if err = c .ovnNbClient .AddLogicalRouterPolicy (c .config .ClusterRouter , util .NodeRouterPolicyPriority , match , action , []string {ip }, externalIDs ); err != nil {
283
+ if err = c .addPolicyRouteToVpc (
284
+ c .config .ClusterRouter ,
285
+ & kubeovnv1.PolicyRoute {
286
+ Priority : util .NodeRouterPolicyPriority ,
287
+ Match : match ,
288
+ Action : action ,
289
+ NextHopIP : ip ,
290
+ },
291
+ externalIDs ,
292
+ ); err != nil {
283
293
klog .Errorf ("failed to add logical router policy for node %s: %v" , node .Name , err )
284
294
return err
285
295
}
@@ -1027,7 +1037,16 @@ func (c *Controller) addNodeGwStaticRoute() error {
1027
1037
if util .CheckProtocol (cidrBlock ) != util .CheckProtocol (nextHop ) {
1028
1038
continue
1029
1039
}
1030
- if err := c .ovnNbClient .AddLogicalRouterStaticRoute (c .config .ClusterRouter , util .MainRouteTable , ovnnb .LogicalRouterStaticRoutePolicyDstIP , cidrBlock , nil , nextHop ); err != nil {
1040
+
1041
+ if err := c .addStaticRouteToVpc (
1042
+ c .config .ClusterRouter ,
1043
+ & kubeovnv1.StaticRoute {
1044
+ Policy : kubeovnv1 .PolicyDst ,
1045
+ CIDR : cidrBlock ,
1046
+ NextHopIP : nextHop ,
1047
+ RouteTable : util .MainRouteTable ,
1048
+ },
1049
+ ); err != nil {
1031
1050
klog .Errorf ("failed to add static route for node gw: %v" , err )
1032
1051
return err
1033
1052
}
@@ -1198,19 +1217,29 @@ func (c *Controller) addPolicyRouteForCentralizedSubnetOnNode(nodeName, nodeIP s
1198
1217
return nil
1199
1218
}
1200
1219
1201
- func (c * Controller ) addPolicyRouteForLocalDnsCacheOnNode (nodePortName , nodeIP , nodeName string , af int ) error {
1202
- externalIDs := map [string ]string {
1203
- "vendor" : util .CniTypeName ,
1204
- "node" : nodeName ,
1205
- "address-family" : strconv .Itoa (af ),
1206
- "isLocalDnsCache" : "true" ,
1207
- }
1208
-
1209
- pgAs := strings .Replace (fmt .Sprintf ("%s_ip%d" , nodePortName , af ), "-" , "." , - 1 )
1210
- match := fmt .Sprintf ("ip%d.src == $%s && ip%d.dst == %s" , af , pgAs , af , c .config .NodeLocalDnsIP )
1211
- action := ovnnb .LogicalRouterPolicyActionReroute
1220
+ func (c * Controller ) addPolicyRouteForLocalDNSCacheOnNode (nodePortName , nodeIP , nodeName string , af int ) error {
1221
+ var (
1222
+ externalIDs = map [string ]string {
1223
+ "vendor" : util .CniTypeName ,
1224
+ "node" : nodeName ,
1225
+ "address-family" : strconv .Itoa (af ),
1226
+ "isLocalDnsCache" : "true" ,
1227
+ }
1228
+ pgAs = strings .ReplaceAll (fmt .Sprintf ("%s_ip%d" , nodePortName , af ), "-" , "." )
1229
+ match = fmt .Sprintf ("ip%d.src == $%s && ip%d.dst == %s" , af , pgAs , af , c .config .NodeLocalDNSIP )
1230
+ action = kubeovnv1 .PolicyRouteActionReroute
1231
+ )
1212
1232
klog .Infof ("add node local dns cache policy route for router: %s, match %s, action %s, nexthop %s, externalID %v" , c .config .ClusterRouter , match , action , nodeIP , externalIDs )
1213
- if err := c .ovnNbClient .AddLogicalRouterPolicy (c .config .ClusterRouter , util .NodeLocalDnsPolicyPriority , match , action , []string {nodeIP }, externalIDs ); err != nil {
1233
+ if err := c .addPolicyRouteToVpc (
1234
+ c .config .ClusterRouter ,
1235
+ & kubeovnv1.PolicyRoute {
1236
+ Priority : util .NodeRouterPolicyPriority ,
1237
+ Match : match ,
1238
+ Action : action ,
1239
+ NextHopIP : nodeIP ,
1240
+ },
1241
+ externalIDs ,
1242
+ ); err != nil {
1214
1243
klog .Errorf ("failed to add logical router policy for node %s: %v" , nodeName , err )
1215
1244
return err
1216
1245
}
0 commit comments