Skip to content

Commit 28c5dd2

Browse files
authored
use table id instead of table name for custom routing tables (#215)
1 parent 5783c30 commit 28c5dd2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

app/controllers/network_routes_controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
)
7070

7171
const (
72-
customRouteTableID = 77
72+
customRouteTableID = "77"
7373
customRouteTableName = "kube-router"
7474
podSubnetsIPSetName = "kube-router-pod-subnets"
7575
nodeAddrsIPSetName = "kube-router-node-ips"
@@ -734,14 +734,14 @@ func (nrc *NetworkRoutingController) injectRoute(path *table.Path) error {
734734
glog.Infof("Tunnel interface: " + tunnelName + " for the node " + nexthop.String() + " already exists.")
735735
}
736736

737-
out, err := exec.Command("ip", "route", "list", "table", customRouteTableName).Output()
737+
out, err := exec.Command("ip", "route", "list", "table", customRouteTableID).Output()
738738
if err != nil {
739739
return fmt.Errorf("Failed to verify if route already exists in %s table: %s",
740740
customRouteTableName, err.Error())
741741
}
742742
if !strings.Contains(string(out), tunnelName) {
743743
if err = exec.Command("ip", "route", "add", nexthop.String(), "dev", tunnelName, "table",
744-
customRouteTableName).Run(); err != nil {
744+
customRouteTableID).Run(); err != nil {
745745
return errors.New("Failed to add route in custom route table due to: " + err.Error())
746746
}
747747
}
@@ -1044,7 +1044,7 @@ func (nrc *NetworkRoutingController) enablePolicyBasedRouting() error {
10441044
}
10451045

10461046
if !strings.Contains(string(out), cidr) {
1047-
err = exec.Command("ip", "rule", "add", "from", cidr, "table", customRouteTableName).Run()
1047+
err = exec.Command("ip", "rule", "add", "from", cidr, "lookup", customRouteTableID).Run()
10481048
if err != nil {
10491049
return fmt.Errorf("Failed to add ip rule due to: %s", err.Error())
10501050
}
@@ -1072,7 +1072,7 @@ func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
10721072
}
10731073

10741074
if strings.Contains(string(out), cidr) {
1075-
err = exec.Command("ip", "rule", "del", "from", cidr, "table", customRouteTableName).Run()
1075+
err = exec.Command("ip", "rule", "del", "from", cidr, "table", customRouteTableID).Run()
10761076
if err != nil {
10771077
return fmt.Errorf("Failed to delete ip rule: %s", err.Error())
10781078
}
@@ -1081,20 +1081,20 @@ func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
10811081
return nil
10821082
}
10831083

1084-
func rtTablesAdd(num uint, s string) error {
1084+
func rtTablesAdd(tableNumber, tableName string) error {
10851085
b, err := ioutil.ReadFile("/etc/iproute2/rt_tables")
10861086
if err != nil {
10871087
return fmt.Errorf("Failed to read: %s", err.Error())
10881088
}
10891089

1090-
if !strings.Contains(string(b), s) {
1090+
if !strings.Contains(string(b), tableName) {
10911091
f, err := os.OpenFile("/etc/iproute2/rt_tables", os.O_APPEND|os.O_WRONLY, 0600)
10921092
if err != nil {
10931093
return fmt.Errorf("Failed to open: %s", err.Error())
10941094
}
1095-
if _, err = f.WriteString(strconv.Itoa(int(num)) + " " + s); err != nil {
1096-
return fmt.Errorf("Failed to write: %s",
1097-
err.Error())
1095+
defer f.Close()
1096+
if _, err = f.WriteString(tableNumber + " " + tableName + "\n"); err != nil {
1097+
return fmt.Errorf("Failed to write: %s", err.Error())
10981098
}
10991099
}
11001100

app/controllers/network_services_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ func setupPolicyRoutingForDSR() error {
12791279
if err != nil {
12801280
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
12811281
}
1282+
defer f.Close()
12821283
if _, err = f.WriteString(customDSRRouteTableID + " " + customDSRRouteTableName + "\n"); err != nil {
12831284
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
12841285
}
@@ -1313,6 +1314,7 @@ func setupRoutesForExternalIPForDSR(serviceInfoMap serviceInfoMap) error {
13131314
if err != nil {
13141315
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
13151316
}
1317+
defer f.Close()
13161318
if _, err = f.WriteString(externalIPRouteTableId + " " + externalIPRouteTableName + "\n"); err != nil {
13171319
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
13181320
}

0 commit comments

Comments
 (0)