6969)
7070
7171const  (
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
0 commit comments