mirror of
https://github.com/cloudnativelabs/kube-router.git
synced 2025-10-07 07:51:26 +02:00
use table id instead of table name for custom routing tables (#215)
This commit is contained in:
parent
5783c30f33
commit
28c5dd20ef
@ -69,7 +69,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
customRouteTableID = 77
|
customRouteTableID = "77"
|
||||||
customRouteTableName = "kube-router"
|
customRouteTableName = "kube-router"
|
||||||
podSubnetsIPSetName = "kube-router-pod-subnets"
|
podSubnetsIPSetName = "kube-router-pod-subnets"
|
||||||
nodeAddrsIPSetName = "kube-router-node-ips"
|
nodeAddrsIPSetName = "kube-router-node-ips"
|
||||||
@ -734,14 +734,14 @@ func (nrc *NetworkRoutingController) injectRoute(path *table.Path) error {
|
|||||||
glog.Infof("Tunnel interface: " + tunnelName + " for the node " + nexthop.String() + " already exists.")
|
glog.Infof("Tunnel interface: " + tunnelName + " for the node " + nexthop.String() + " already exists.")
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := exec.Command("ip", "route", "list", "table", customRouteTableName).Output()
|
out, err := exec.Command("ip", "route", "list", "table", customRouteTableID).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to verify if route already exists in %s table: %s",
|
return fmt.Errorf("Failed to verify if route already exists in %s table: %s",
|
||||||
customRouteTableName, err.Error())
|
customRouteTableName, err.Error())
|
||||||
}
|
}
|
||||||
if !strings.Contains(string(out), tunnelName) {
|
if !strings.Contains(string(out), tunnelName) {
|
||||||
if err = exec.Command("ip", "route", "add", nexthop.String(), "dev", tunnelName, "table",
|
if err = exec.Command("ip", "route", "add", nexthop.String(), "dev", tunnelName, "table",
|
||||||
customRouteTableName).Run(); err != nil {
|
customRouteTableID).Run(); err != nil {
|
||||||
return errors.New("Failed to add route in custom route table due to: " + err.Error())
|
return errors.New("Failed to add route in custom route table due to: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1044,7 +1044,7 @@ func (nrc *NetworkRoutingController) enablePolicyBasedRouting() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(string(out), cidr) {
|
if !strings.Contains(string(out), cidr) {
|
||||||
err = exec.Command("ip", "rule", "add", "from", cidr, "table", customRouteTableName).Run()
|
err = exec.Command("ip", "rule", "add", "from", cidr, "lookup", customRouteTableID).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to add ip rule due to: %s", err.Error())
|
return fmt.Errorf("Failed to add ip rule due to: %s", err.Error())
|
||||||
}
|
}
|
||||||
@ -1072,7 +1072,7 @@ func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(string(out), cidr) {
|
if strings.Contains(string(out), cidr) {
|
||||||
err = exec.Command("ip", "rule", "del", "from", cidr, "table", customRouteTableName).Run()
|
err = exec.Command("ip", "rule", "del", "from", cidr, "table", customRouteTableID).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to delete ip rule: %s", err.Error())
|
return fmt.Errorf("Failed to delete ip rule: %s", err.Error())
|
||||||
}
|
}
|
||||||
@ -1081,20 +1081,20 @@ func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func rtTablesAdd(num uint, s string) error {
|
func rtTablesAdd(tableNumber, tableName string) error {
|
||||||
b, err := ioutil.ReadFile("/etc/iproute2/rt_tables")
|
b, err := ioutil.ReadFile("/etc/iproute2/rt_tables")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to read: %s", err.Error())
|
return fmt.Errorf("Failed to read: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(string(b), s) {
|
if !strings.Contains(string(b), tableName) {
|
||||||
f, err := os.OpenFile("/etc/iproute2/rt_tables", os.O_APPEND|os.O_WRONLY, 0600)
|
f, err := os.OpenFile("/etc/iproute2/rt_tables", os.O_APPEND|os.O_WRONLY, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to open: %s", err.Error())
|
return fmt.Errorf("Failed to open: %s", err.Error())
|
||||||
}
|
}
|
||||||
if _, err = f.WriteString(strconv.Itoa(int(num)) + " " + s); err != nil {
|
defer f.Close()
|
||||||
return fmt.Errorf("Failed to write: %s",
|
if _, err = f.WriteString(tableNumber + " " + tableName + "\n"); err != nil {
|
||||||
err.Error())
|
return fmt.Errorf("Failed to write: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1279,6 +1279,7 @@ func setupPolicyRoutingForDSR() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
|
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
if _, err = f.WriteString(customDSRRouteTableID + " " + customDSRRouteTableName + "\n"); err != nil {
|
if _, err = f.WriteString(customDSRRouteTableID + " " + customDSRRouteTableName + "\n"); err != nil {
|
||||||
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
|
return errors.New("Failed to setup policy routing required for DSR due to " + err.Error())
|
||||||
}
|
}
|
||||||
@ -1313,6 +1314,7 @@ func setupRoutesForExternalIPForDSR(serviceInfoMap serviceInfoMap) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
|
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
if _, err = f.WriteString(externalIPRouteTableId + " " + externalIPRouteTableName + "\n"); err != nil {
|
if _, err = f.WriteString(externalIPRouteTableId + " " + externalIPRouteTableName + "\n"); err != nil {
|
||||||
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
|
return errors.New("Failed setup external ip routing table required for DSR due to " + err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user